private void tabControl1_ControlAdded(object sender, ControlEventArgs e) { enterBootloaderToolStripMenuItem.Enabled = false; if (tabControl1.SelectedTab != null) { NavitarControl control = tabControl1.SelectedTab.Controls[0] as NavitarControl; Controller controller = control.MyController; if (controller.Generation == 2) { enterBootloaderToolStripMenuItem.Enabled = true; } } }
private void enterBootloaderToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl1.SelectedTab == null) { return; } NavitarControl control = tabControl1.SelectedTab.Controls[0] as NavitarControl; Controller controller = control.MyController; if (controller.Generation == 2) { ControllerGen2 secondGen = controller as ControllerGen2; // Get rid of tab TabPage page = tabControl1.SelectedTab; tabControl1.TabPages.Remove(page); page.Dispose(); // Set wait cursor since operation takes a few seconds. Cursor.Current = Cursors.WaitCursor; // Enter bootloader secondGen.EnterBootloader(); ControllerHub.RemoveController(secondGen); // Be patient while USB CDC device drops off bus. System.Threading.Thread.Sleep(2500); // Clear the wait cursor. Cursor.Current = Cursors.Default; } else { MessageBox.Show("Enter Bootloader command not supported for this controller.", "Feature Not Supported", MessageBoxButtons.OK); } }