Text in English Updating UI in .NET

In old MFC, there was an WM_IDLE event where you could examine the state of your program, and update menu items, buttons and the like accordingly to gray them out, add or delete options... This event was fired whenever the Windows message queue for your application became empty.

To mimic the same behaviour in .NET, you can build sort of an OnIdle event. First, the definition of the handler method, wich could go in the main form:

private void OnApplicationIdle(object sender, EventArgs e)

And then, registering that handler for the proper event. You can add the following at (for instance) the Load event of the main form:

System.Windows.Forms.Application.Idle += new EventHandler(OnApplicationIdle);

In OnApplicationIdle it's up to you to check things (for instance, you can see whether there is any document open, and gray out the "Close" menu option if there isn't).

No hay comentarios: