首页 \ 问答 \ WinForms中的按钮有一个CLICK事件。(The Button in WinForms has a CLICK event. But who tells the Button object that it has been clicked?)

WinForms中的按钮有一个CLICK事件。(The Button in WinForms has a CLICK event. But who tells the Button object that it has been clicked?)

我正在学习C#。 我正在浏览该语言的事件和代表部分。 我正在开发一个用于教育自己的WinForms应用程序。 我试图深入了解Buttons以及它们是如何工作的。 我发现以下内容:

1)在我的默认Form1.cs文件中有一行public partial class Form1 : Form 。 这是一个部分课程。

2)我也有一个Form1.Designer.cs类文件,它具有一个行部partial class Form1 。 现在1)和2)中提到的文件组合起来形成一个完整的课程。

3)From1.Designer.cs文件有很多最终创建按钮对象的语句。 它还有一个我特别感兴趣的声明:

this.btn_BaseBuildLocation.Click += new System.EventHandler(this.btn_BaseBuildLocation_Click);

此语句将自定义函数添加到委托单击。 该委托在Control类(System.Windows.Forms.dll)中声明如下:

public event EventHandler Click;

4)EventHandler是在System.EventHandler.cs(mscorlib.dll)中定义的委托。

5)Button类继承Control类,因此可以访问Click EventHandler。

6)一旦知道某人点击了它,Button类就具有处理该流的所有逻辑。 我查看了Mono中用于了解内部细节的Button类。 我为几乎所有我想学习的课程都这样做。

7)所有这些都非常漂亮。 但是我很困惑,因为我不知道Button对象是如何知道它已被点击的。

8)我经历了VC ++以及它如何处理事件。 我发现很多关于消息循环,事件队列等等......

问题:

1)处理事件的VC ++方式是否与.NET相同?

2)如果是这样,有没有办法查看这些细节?

任何帮助,将不胜感激。 谢谢。


I am learning C#. I was going through the Events and Delegates part of the language. I am working on a WinForms application for educating myself. I tried looking deep for understanding Buttons and how they work. I found the following:

1) There is a line public partial class Form1 : Form in my default Form1.cs file. This is a partial class.

2) I also have a Form1.Designer.cs class file that has a line partial class Form1. Now the files mentioned in 1) and 2) combine to form a full class.

3) The From1.Designer.cs file has a lot of statements that eventually create the button object. It also has a statement that is of particular interest to me:

this.btn_BaseBuildLocation.Click += new System.EventHandler(this.btn_BaseBuildLocation_Click);

This statement adds a custom function to the delegate Click. This delegate is declared in the Control class (System.Windows.Forms.dll) as follows:

public event EventHandler Click;

4) The EventHandler is a delegate defined in System.EventHandler.cs (mscorlib.dll).

5) The Button class inherits Control class and thus has access to the Click EventHandler.

6) The Button class has all the logic to handle the flow once it knows that someone has clicked it. I had a look at the Button class used in Mono for understanding the inner details. I do this for almost all classes that I want to learn.

7) All this is extremely beautiful. But I was troubled by the fact that I did not know how the Button object knows that it has been clicked.

8) I went through VC++ and how it handles the events. I found a lot about Message Loops, Event Queues etc...

Questions:

1) Is the VC++ way of handling events the same as .NET's?

2) If so, is there a way to look into those details?

Any help would be appreciated. Thanks.


原文:https://stackoverflow.com/questions/17649233
更新时间:2022-06-06 17:06

最满意答案

MSBuild没有新版本,您仍然使用4.5


There is no new version of MSBuild, you still use 4.5

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。