简体   繁体   English

如何在Visual Studio中为自定义控件设置要编辑的默认事件?

[英]How can I set the default event to be edited for my custom control in Visual Studio?

I made a custom button by inheriting the Button class. 我通过继承Button类创建了一个自定义按钮。 When I double click the custom button in Designer, it makes the event handling function for MyButton.Click: 当我在Designer中双击自定义按钮时,它会为MyButton.Click创建事件处理函数:

Private Sub MyButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton1.Click

    End Sub

How can I make it so that when you double click, it makes the event handling function for another event? 我如何才能使它在双击时使事件处理功能成为另一个事件? For example, MyButton.KeyUp: 例如,MyButton.KeyUp:

Private Sub MyButton1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyButton1.KeyUp

    End Sub

Hopefully, someone can help me with this. 希望有人可以帮助我。

使用DefaultEventAttribute

<DefaultEvent("KeyUp")> Public Class MyButton

Have you tried the DefaultEvent attribute ? 您是否尝试过DefaultEvent属性

Example from MSDN: 来自MSDN的示例:

<DefaultEvent("CollectionChanged")> _ 
Public Class MyCollection
    Inherits BaseCollection

    Public Event CollectionChanged (ByVal sender As Object, _
        ByVal e As CollectionChangeEventArgs)

    ' Insert additional code.
End Class 'MyCollection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 2017 中设置默认浏览器? - How do I set the default browser in Visual Studio 2017? 如何创建具有可在设计器中编辑的IPAddress属性的控件? - How can I create a control with IPAddress properties that can be edited in the designer? 如何将自定义默认构建操作与Visual Studio中的自定义文件类型相关联? - How do I associate a custom default build action to a custom file type in Visual Studio? 如何在 Visual Studio 中的引用代码中设置断点? - How can I set a breakpoint in referenced code in Visual Studio? 如何在我的代码中调用控制事件? - How can I call a control event in my code? 如何将 jQuery DateTimePicker 添加到我在 visual studio 中的项目 - How can I add jQuery DateTimePicker to my project in visual studio 如何将自定义Windows窗体控件添加到Visual Studio工具箱 - How to add a Custom Windows Forms Control into Visual Studio Toolbox 我怎么有一个ControlTemplate只能为控件的默认,未更改的可视树创建一个容器? - How can I have a ControlTemplate that only creates a container for the default, unaltered visual tree of a control? 如何在Visual Studio解决方案文件中设置默认配置? - How to set a default configuration in a Visual Studio Solution File? 如何在Winforms的自定义控件中设置Colors的默认值? - How to set the default value of Colors in a custom control in Winforms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM