WinForms: temporarily disable an event handler

Probably, the simplest way (which doesn’t need unsubscribing or other stuff) is to declare a boolean value and check it at the beginning of the handler:

bool dontRunHandler;

void Handler(object sender, EventArgs e) {
   if (dontRunHandler) return;

   // handler body...
}

Leave a Comment