I have a C# class library. In that class I have declared an event as a property
private static event MouseEventHandler s_MouseClick;
public static event MouseEventHandler MouseClick
{
add
{
s_MouseClick += value;
}
remove
{
s_MouseClick -= value;
}
}
I have another project written in VB.net, On click of a button I want to do something like this:
cls.MouseClick += cls_MouseClick;
void cls_MouseClick(object sender, KeyPressEventArgs e)
{
}
This is how I would do it in C#. But how do I do it in VB?
In VB, to register an event handler use
AddHandler:Use
RemoveHandlerto unregister the event handler.Alternatively, you can use a declarative syntax. That is: declare the member as follows:
And declare the handler like this:
Now you do not need to register the handler manually.