在 Visual Studio 设计器中为控件指定双击事件 [英] Specify Double-Click event for a Control in Visual Studio Designer

查看:33
本文介绍了在 Visual Studio 设计器中为控件指定双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在 Visual Studio 设计器中双击 Control 时,您会自动订阅一些 事件,并在代码隐藏文件中生成一个事件处理程序.

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 - 已加载
  • 按钮 - 点击
  • TextBox - TextChanged
  • Grid - 无事件
  • UserControl - Loaded
  • Button - Click
  • TextBox - TextChanged
  • Grid - 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 设计器中为控件指定双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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