Custom Control
-
Hi guys I am making a custom control/user control. How make mycontrol.dosomething(); fire an event and How do I handle event handlers Thanks
-
Hi guys I am making a custom control/user control. How make mycontrol.dosomething(); fire an event and How do I handle event handlers Thanks
public class MyControl : Control
{
public event EventHandler DoingSomething;public void DoSomething() { OnDoingSomething(EventArgs.Empty); } protected virtual void OnDoingSomething(EventArgs e) { EventHandler eh = DoingSomething; if(eh != null) eh(this, e); }
}
The event handler for this event can be done in the same way as any other control. See my Events Made Simple[^] article for more info including custom event args etc.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
public class MyControl : Control
{
public event EventHandler DoingSomething;public void DoSomething() { OnDoingSomething(EventArgs.Empty); } protected virtual void OnDoingSomething(EventArgs e) { EventHandler eh = DoingSomething; if(eh != null) eh(this, e); }
}
The event handler for this event can be done in the same way as any other control. See my Events Made Simple[^] article for more info including custom event args etc.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)Thank you