The best way to enable and disable buttons, menu items and toolbar buttons | |||
| |||
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; } Tags: C# Disable Menu Disable Toolbar Buttons Enable Button Enable Menu Enable Toolbar Buttons Hook in the OnIdle method Memory leak detection | |||
| |||
| |||
Login for comment |