在对话框中提取和显示参数? [英] Extract and display parameter in a dialog?

查看:28
本文介绍了在对话框中提取和显示参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个小项目并将其打包到 GUI 中.参考源代码是DrawTools(下载源代码 - 61.1 Kb).

I am working on a small project and packing it into GUI. The reference source code is DrawTools(Download source code - 61.1 Kb).

参考源代码演示了 C# WinForms 中的绘图工具.

The reference source code demos a drawing tool in C# WinForms.

功能是绘制矩形、椭圆、多边形等不同的图形

The function is to draw different figures like rectangle, ellipse, polygon, etc.

我想利用这些图形的位置和大小信息做进一步的工作,所以如果我在绘图区画一个矩形,C#WinForms是否可以返回这个图形的参数(例如x,y,width,height在 DrawRectangle.cs)?

I want to use the location and size information of these figures to do further work, so if I draw a rectangle in the draw area, could C# WinForms returns the parameter of this figure(eg. x,y,width,height in the DrawRectangle.cs)?

代码如下:

public DrawRectangle(int x, int y, int width, int height)
    {
        rectangle.X = x;
        rectangle.Y = y;
        rectangle.Width = width;
        rectangle.Height = height;
        Initialize();
    }

另外,如何获取返回的参数然后在新的对话框中显示?

Further more, How to get the returned parameters and then displayed in a new dialog?

推荐答案

您可以添加一些事件来支持通知正在发生的事情,例如:

You can add some event to support notifying what is happening, something like this:

public class InitRectangleEventArgs : EventArgs {
   public Rectangle Rectangle {get;set;}
}
public delegate void InitRectangleEventHandler(object sender, InitRectangleEventArgs e);
public event InitRectangleEventHandler InitRectangle;
public DrawRectangle(int x, int y, int width, int height)
{
    rectangle.X = x;
    rectangle.Y = y;
    rectangle.Width = width;
    rectangle.Height = height;
    if(InitRectangle != null) InitRectangle(this, new InitRectangleEventArgs { Rectangle = new Rectangle(x,y,width,height)});
    Initialize();
}
//To use it, just subscribe the event so that you can know the 
//info of the Rectangle everytime it is initialized
InitRectangle += (s,e) => {
  //Get the info from the Rectangle property of e:   e.Rectangle
  //....
};

这篇关于在对话框中提取和显示参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆