| Write an OnIdle method and put your GUI enable/disable code there. The OnIdle method is called every time your application's message queue becomes empty.
Hook in the OnIdle method in a Form's constructor by instantiating an EventHandler and adding that hander to the Application object's Idle property. Update the form's GUI in the OnIdle method. Finally, be sure to remove the EventHandler from the Application object's Idle property when the Form is about to close.
...
private EventHandler idleEventHandler;
...
public SettingsForm(InitialTabPage initialTabPage)
{
InitializeComponent();
...
idleEventHandler = new System.EventHandler(OnIdle);
Application.Idle += idleEventHandler;
}
...
private void OnIdle(object sender, EventArgs e)
{
// Update form's UI when program is idle.
deleteButton.Enabled = assemblyListBox.SelectedIndex != -1;
}
private void SettingsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
...
Application.Idle -= idleEventHandler;
}
|