在Visual Studio Designer中为控件指定双击事件 [英] Specify Double-Click event for a Control in Visual Studio Designer
问题描述
当您在Visual Studio设计器中双击Control
时,您将自动订阅一些event
,并且在文件后面的代码中会生成一个事件处理程序.
When you Double-Click on a Control
in the Visual Studio Designer, you automatically subscribe to some event
and an Event Handler is generated in the code behind file.
双击以下控件即可订阅相应的事件
Double-Clicking on the following Controls subscribes to the corresponding event
-
UserControl
-已加载 -
Button
-点击 -
TextBox
- TextChanged -
Grid
-没有事件
等
UserControl
- LoadedButton
- ClickTextBox
- TextChangedGrid
- No event
etc.
这是如何指定的,它是Visual Studio设置吗?可以覆盖此事件吗?如何指定要链接到Double-Click的事件,例如自定义控件?
How is this specified, is it a Visual Studio setting? Can this be overrideen and how can you specify which event you want to link to Double-Click for e.g. a Custom Control?
谢谢
推荐答案
有一个 DefaultEventAttribute .设计者知道要读取此属性,并使用它来确定将哪个事件用作默认事件.
There is a DefaultEventAttribute that controls can specify. The designer knows to read this attribute and uses it to determine which event to use as the default.
[DefaultEvent("DoubleClick")]
public class MyClass {
public event EventHandler DoubleClick;
}
还有一个DefaultPropertyAttribute,它的用途明显不足.它只是确定在设计器中选择控件时要在属性网格中选择的默认属性名称.
There is also a DefaultPropertyAttribute which is significantly less useful. It just determines the default property name to select in the property grid when the control is selected in the designer.
这篇关于在Visual Studio Designer中为控件指定双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!