Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin example21 Update: size and resize of the buttons. #3216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 134 additions & 81 deletions Plugins/example21-persistentsimple.cs
Original file line number Diff line number Diff line change
@@ -1,86 +1,139 @@
using System;
using System.Windows.Forms;
using MissionPlanner;
using MissionPlanner.Plugin;
using MissionPlanner.Controls;

namespace PersistentSimpleActions
{
public class PersistentSimpleActions : Plugin
{
private string _Name = "Persistent Simple Actions";
private string _Version = "0.1";
private string _Author = "Bob Long";

public override string Name { get { return _Name; } }
public override string Version { get { return _Version; } }
public override string Author { get { return _Author; } }

// CHANGE THIS TO TRUE TO USE THIS PLUGIN
public override bool Init() { return false; }

public override bool Loaded()
using System;
using System.Windows.Forms;
using System.Drawing;
using MissionPlanner;
using MissionPlanner.Plugin;
using MissionPlanner.Controls;

namespace PersistentSimpleActions
{
public class PersistentSimpleActions : Plugin
{
private string _Name = "Persistent Simple Actions";
private string _Version = "0.2";
private string _Author = "Bob Long";

public override string Name { get { return _Name; } }
public override string Version { get { return _Version; } }
public override string Author { get { return _Author; } }

MyButton button1 = new MyButton();
MyButton button2 = new MyButton();
MyButton button3 = new MyButton();
ToolTip toolTip1 = new ToolTip();

// CHANGE THIS TO TRUE TO USE THIS PLUGIN
public override bool Init() { return false; }

public override bool Loaded()
{
MyButton button1 = new MyButton();
MyButton button2 = new MyButton();
MyButton button3 = new MyButton();
ToolTip toolTip1 = new ToolTip();

// Rename these .Text fields to any valid mode and the code will automatically work
button1.Text = "Auto";
button2.Text = "Loiter";
button3.Text = "RTL";

//
// button1
//
button1.Location = new System.Drawing.Point(4, 4);
button1.Size = new System.Drawing.Size(75, 23);
toolTip1.SetToolTip(button1, "Change mode to " + button1.Text);
button1.Click += new EventHandler(but_mode_Click);
//
// button2
//
button2.Location = new System.Drawing.Point(85, 4);
button2.Size = new System.Drawing.Size(75, 23);
toolTip1.SetToolTip(button2, "Change mode to " + button2.Text);
button2.Click += new EventHandler(but_mode_Click);
//
// button3
//
button3.Location = new System.Drawing.Point(166, 4);
button3.Size = new System.Drawing.Size(75, 23);
toolTip1.SetToolTip(button3, "Change mode to " + button3.Text);
button3.Click += new EventHandler(but_mode_Click);

// Increase the minimum size of the persistent panel. Not necessary, but adds a little
// more gap between the buttons and the tabs.
// Rename these .Text fields to any valid mode and the code will automatically work
button1.Text = "Auto";
button2.Text = "Loiter";
button3.Text = "RTL";

//Make a variable for positioning the Controls on the Panel Persistant Panel
var panelPosition = 3;

//Varaible for the button one location X
var buttonOneLocationX = panelPosition + 3;
//Set the button's width
var buttonOneWidth = button1.Width;

// Increase the minimum size of the persistent panel. Not necessary, but adds a little
// more gap between the buttons and the tabs.
MainV2.instance.FlightData.panel_persistent.MinimumSize = new System.Drawing.Size(0, 35);

//
// button1
//
//Location of the button
button1.Location = new Point((int)(buttonOneLocationX), (int)(3));
button1.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
toolTip1.SetToolTip(button1, "Change mode to " + button1.Text);
button1.Click += new EventHandler(but_mode_Click);
//
// button2
//
//Variable for location X of Button 2
var buttonTwoLocationX = button1.Right + 7;
button2.Location = new Point((int)(buttonTwoLocationX), (int)(3));
button2.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
toolTip1.SetToolTip(button2, "Change mode to " + button2.Text);
button2.Click += new EventHandler(but_mode_Click);
//
// button3
//
//Variable for location X of Button 3
var buttonThreeLocationX = button2.Right + 7;
button3.Location = new System.Drawing.Point(buttonThreeLocationX, (int)(3));
button3.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
toolTip1.SetToolTip(button3, "Change mode to " + button3.Text);
button3.Click += new EventHandler(but_mode_Click);

// Add the buttons
MainV2.instance.FlightData.panel_persistent.Controls.Add(button1);
MainV2.instance.FlightData.panel_persistent.Controls.Add(button2);
MainV2.instance.FlightData.panel_persistent.Controls.Add(button3);

return true;
}

public override bool Exit() { return true; }

private void but_mode_Click(object sender, EventArgs e)
{
try
{
((Control)sender).Enabled = false;
MainV2.comPort.setMode(((Control)sender).Text);
}
catch
{
CustomMessageBox.Show(Strings.CommandFailed, Strings.ERROR);
}

((Control)sender).Enabled = true;
}

}
MainV2.instance.FlightData.panel_persistent.Controls.Add(button1);
MainV2.instance.FlightData.panel_persistent.Controls.Add(button2);
MainV2.instance.FlightData.panel_persistent.Controls.Add(button3);

//Resizing Controls on Persistent Panel
MainV2.instance.FlightData.panel_persistent.Resize += new EventHandler(Controls_Resize);

return true;
}

private void Controls_Resize(object sender, EventArgs e)
{
//Make a variable for positioning the Controls on the Panel Persistant Panel
var panelPosition = 3;

//Varaible for the button location X
var buttonOneLocationX = panelPosition + 3;
//Set the button's width
var buttonOneWidth = button1.Width;

// Increase the minimum size of the persistent panel. Not necessary, but adds a little
// more gap between the buttons and the tabs.
MainV2.instance.FlightData.panel_persistent.MinimumSize = new System.Drawing.Size(0, 35);

//
// button1
//
//Location of the button
button1.Location = new Point((int)(buttonOneLocationX), (int)(3));
button1.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
//
// button2
//
//Variable for location X of Button 2
var buttonTwoLocationX = button1.Right + 7;
button2.Location = new Point((int)(buttonTwoLocationX), (int)(3));
button2.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
//
// button3
//
//Variable for location X of Button 3
var buttonThreeLocationX = button2.Right + 7;
button3.Location = new System.Drawing.Point(buttonThreeLocationX, (int)(3));
button3.Size = new Size((int)(MainV2.instance.FlightData.panel_persistent.Width * 0.14), (int)(MainV2.instance.FlightData.panel_persistent.Height * 0.6));
}

public override bool Exit() { return true; }

private void but_mode_Click(object sender, EventArgs e)
{
try
{
((Control)sender).Enabled = false;
MainV2.comPort.setMode(((Control)sender).Text);
}
catch
{
CustomMessageBox.Show(Strings.CommandFailed, Strings.ERROR);
}

((Control)sender).Enabled = true;
}

}
}
Loading