[英]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.