How can I set a default edit event for my custom control in Visual Studio?

I created a custom button, inheriting the Button class. When I double-click the user button in Designer, this makes the event handling function for 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 I double-click it makes the event-handling function for another event? For example, MyButton.KeyUp:

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

Hope someone can help me.

+4
source share
2 answers

use DefaultEventAttribute :

 <DefaultEvent("KeyUp")> Public Class MyButton 
+10
source

Have you tried the DefaultEvent attribute ?

Example from 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 
+7
source

All Articles