English 中文(简体)
在classname.designer.cs文件中自动设置事件处理程序。
原标题:
  • 时间:2008-11-21 19:01:04
  •  标签:

Is there any way to set an event handler without doing it manually in the classname.designer.cs file other than double clicking the UI element?

最佳回答

Click on the lightning bolt icon in the Properties window. Double-click the event you want to implement.

问题回答

If I follow your question correctly, you can just do it in your code-behind like this:

myButton.Click += myHandler;

Or you could use an anonymous delegate:

myButton.Click += delegate
{
    MessageBox.Show("Clicked!");
};

当然。在初始化过程中某个地方(如窗体的构造函数中),使用myControl.Event += new EventHandler(SomeHandlerMethodInYourClass)





相关问题
热门标签