Search results for 'Hook in the OnIdle method'. 1 post(s) found.

  1. 2007/09/25 The best way to enable and disable buttons, menu items and toolbar buttons
2007/09/25 14:59

The best way to enable and disable buttons, menu items and toolbar buttons


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;
}

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 03:32 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:37 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:41 delete

    moneyideas