disable event handler

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,

Is there a way to disable an event handler, like a clik on a button
at a certain stage of the program.


Thanks in Advance
 
Is there a way to disable an event handler, like a clik on a button
at a certain stage of the program.

there are several possibilities here.

you could for example add a boolean control variable to your class and
inside the event handler test the variable:

void bt_Click(...)
{
if ( controlVariable )
{
// handle the event
}
}

you could also just remove the delegate from the event:

bt.Click -= new EventHandler( eventHandler );

and add it again when necessary:

bt.Click += new EventHandler( eventHandler );

regards,
Wiktor Zychla
 
Similar to the way you add an event handler, you can easly remove it by
using -=

Enable event handler
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);

Disable event handler
this.btnBrowse.Click -= new System.EventHandler(this.btnBrowse_Click);
Hope that helps
Rob Vretenar [imason inc.]
 
Back
Top