public void ShowScreen(string name)
{
if (current != null && current.Control != null)
{
// hide current screen
current.Visible = false;
// remove reference
MainControl.Controls.Remove(current.Control);
if (current.Control is IDeactivate)
{
((IDeactivate)(current.Control)).Deactivate();
}
// check if we need to remove the current control
if (!current.Persistent)
{
// cleanup
current.Control.Close();
current.Control.Dispose();
current.Control = null;
GC.Collect();
}
}
if (name == "")
return;
// find next screen
Screen nextscreen = screens.Single(s => s.Name == name);
// screen name dosnt exist
if (nextscreen == null)
return;
// screen control is null, create it
if (nextscreen.Control == null || nextscreen.Control.IsDisposed)
CreateControl(nextscreen);
MainControl.SuspendLayout();
nextscreen.Control.SuspendLayout();
nextscreen.Control.Location = new Point(0, 0);
nextscreen.Control.AutoScaleMode = AutoScaleMode.None;
nextscreen.Control.Size = MainControl.Size;
nextscreen.Control.Dock = DockStyle.Fill;
MissionPlanner.Utilities.Tracking.AddPage(nextscreen.Control.GetType().ToString(), name);
if (nextscreen.Control is IActivate)
{
((IActivate)(nextscreen.Control)).Activate();
}
if (ApplyTheme != null)
ApplyTheme(nextscreen.Control);
if (MainControl.InvokeRequired)
{
MainControl.Invoke((MethodInvoker)delegate
{
MainControl.Controls.Add(nextscreen.Control);
nextscreen.Control.ResumeLayout();
MainControl.ResumeLayout();
});
}
else
{
MainControl.Controls.Add(nextscreen.Control);
nextscreen.Control.ResumeLayout();
MainControl.ResumeLayout();
}
nextscreen.Control.Refresh();
nextscreen.Visible = true;
current = nextscreen;
current.Control.Focus();
}
public Wizard() { instance = this; InitializeComponent(); Utilities.ThemeManager.ApplyThemeTo(this); config.Clear(); wiz_main = new MainSwitcher(this.panel1); wiz_main.AddScreen(new MainSwitcher.Screen("Intro", new _1Intro(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("FrameFW", new _2FrameFW(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("Connect", new _3ConnectAP(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("FrameType", new _4FrameType(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("AccelCalib", new _5AccelCalib(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("CompassCalib", new _6CompassCalib(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("BatteryMonitor", new _7BatteryMonitor(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("OptionalAC", new _8OptionalItemsAC(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("OptionalAP", new _8OptionalItemsAP(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("Radio Calib", new _9RadioCalibration(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("Flight Modes",new _10FlightModes(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("Verify", new _11Verify(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("Failsafe", new _12FailSafe(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("GeoFence", new _13GeoFence(), true)); wiz_main.AddScreen(new MainSwitcher.Screen("DontForget", new _98DontForget(), true)); if (MainV2.comPort.BaseStream.IsOpen) { if (MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.FIXED_WING) { wiz_main.ShowScreen("AccelCalib"); } else if (MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.HELICOPTER || MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.HEXAROTOR || MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.OCTOROTOR || MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.QUADROTOR || MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.TRICOPTER) { wiz_main.ShowScreen("FrameType"); } else { wiz_main.ShowScreen("Intro"); } } else { wiz_main.ShowScreen("Intro"); } history.Add(wiz_main.current.Name); progressStep1.Maximum = wiz_main.screens.Count + 1; progressStep1.Step = 1; }