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).



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

A %d blogueros les gusta esto: