From d75b2b17d3a7331d9e27c14e66961075910ed91e Mon Sep 17 00:00:00 2001 From: Falco Date: Sat, 30 Sep 2023 22:22:44 +0200 Subject: [PATCH] - Adds FormMessage to replace MessageBox - Replace all MessageBoxes with FormMessage to show in center parent and always top - Makes FormPoint deleter show automatically on construction with parent parameter - Makes FormStartingPoint show automatically on construction with parent parameter - Removes unneccessary using clauses from FormAskBinaryQuestion - Bump version to 0.5.10 --- .../CoordinateConverter.csproj | 9 ++ .../DCS/Tools/FormAH64PointDeleter.cs | 4 +- .../DCS/Tools/FormAskBinaryQuestion.cs | 7 - .../DCS/Tools/FormMessage.Designer.cs | 78 ++++++++++++ CoordinateConverter/DCS/Tools/FormMessage.cs | 70 ++++++++++ .../DCS/Tools/FormMessage.resx | 120 ++++++++++++++++++ .../DCS/Tools/FormStartingWaypoint.cs | 4 +- .../DCS/Tools/FormUnitImporter.cs | 7 +- CoordinateConverter/MainForm.cs | 26 ++-- 9 files changed, 299 insertions(+), 26 deletions(-) create mode 100644 CoordinateConverter/DCS/Tools/FormMessage.Designer.cs create mode 100644 CoordinateConverter/DCS/Tools/FormMessage.cs create mode 100644 CoordinateConverter/DCS/Tools/FormMessage.resx diff --git a/CoordinateConverter/CoordinateConverter.csproj b/CoordinateConverter/CoordinateConverter.csproj index 395a1c9..01dec7b 100644 --- a/CoordinateConverter/CoordinateConverter.csproj +++ b/CoordinateConverter/CoordinateConverter.csproj @@ -111,6 +111,12 @@ FormUnitImporter.cs + + Form + + + FormMessage.cs + Form @@ -133,6 +139,9 @@ FormAskBinaryQuestion.cs + + FormMessage.cs + FormStartingWaypoint.cs diff --git a/CoordinateConverter/DCS/Tools/FormAH64PointDeleter.cs b/CoordinateConverter/DCS/Tools/FormAH64PointDeleter.cs index 9460d55..bcf380b 100644 --- a/CoordinateConverter/DCS/Tools/FormAH64PointDeleter.cs +++ b/CoordinateConverter/DCS/Tools/FormAH64PointDeleter.cs @@ -21,7 +21,7 @@ public partial class FormAH64PointDeleter : Form /// /// Initializes a new instance of the class. /// - public FormAH64PointDeleter(AH64 selectedAircraft) + public FormAH64PointDeleter(Form parent, AH64 selectedAircraft) { InitializeComponent(); cb_PointType.Items.Clear(); @@ -33,6 +33,8 @@ public FormAH64PointDeleter(AH64 selectedAircraft) cb_PointType.SelectedIndex = 0; this.selectedAircraft = selectedAircraft; + + ShowDialog(parent); } private void Cb_PointType_SelectedIndexChanged(object objSender, EventArgs e) diff --git a/CoordinateConverter/DCS/Tools/FormAskBinaryQuestion.cs b/CoordinateConverter/DCS/Tools/FormAskBinaryQuestion.cs index 57955b4..2338a16 100644 --- a/CoordinateConverter/DCS/Tools/FormAskBinaryQuestion.cs +++ b/CoordinateConverter/DCS/Tools/FormAskBinaryQuestion.cs @@ -1,12 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace CoordinateConverter.DCS.Tools diff --git a/CoordinateConverter/DCS/Tools/FormMessage.Designer.cs b/CoordinateConverter/DCS/Tools/FormMessage.Designer.cs new file mode 100644 index 0000000..063565a --- /dev/null +++ b/CoordinateConverter/DCS/Tools/FormMessage.Designer.cs @@ -0,0 +1,78 @@ +namespace CoordinateConverter.DCS.Tools +{ + partial class FormMessage + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lbl_Message = new System.Windows.Forms.Label(); + this.btn_Accept = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lbl_Message + // + this.lbl_Message.AutoSize = true; + this.lbl_Message.Location = new System.Drawing.Point(13, 13); + this.lbl_Message.Name = "lbl_Message"; + this.lbl_Message.Size = new System.Drawing.Size(53, 13); + this.lbl_Message.TabIndex = 0; + this.lbl_Message.Text = "Message!"; + // + // btn_Accept + // + this.btn_Accept.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btn_Accept.Location = new System.Drawing.Point(70, 37); + this.btn_Accept.Name = "btn_Accept"; + this.btn_Accept.Size = new System.Drawing.Size(75, 23); + this.btn_Accept.TabIndex = 1; + this.btn_Accept.Text = "OK"; + this.btn_Accept.UseVisualStyleBackColor = true; + this.btn_Accept.Click += new System.EventHandler(this.Btn_Accept_Click); + // + // FormMessage + // + this.AcceptButton = this.btn_Accept; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(157, 72); + this.Controls.Add(this.btn_Accept); + this.Controls.Add(this.lbl_Message); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "FormMessage"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Message"; + this.TopMost = true; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lbl_Message; + private System.Windows.Forms.Button btn_Accept; + } +} \ No newline at end of file diff --git a/CoordinateConverter/DCS/Tools/FormMessage.cs b/CoordinateConverter/DCS/Tools/FormMessage.cs new file mode 100644 index 0000000..07839c5 --- /dev/null +++ b/CoordinateConverter/DCS/Tools/FormMessage.cs @@ -0,0 +1,70 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace CoordinateConverter.DCS.Tools +{ + /// + /// A form to display a simple message to the user + /// + /// + public partial class FormMessage : Form + { + + /// + /// Initializes a new instance of the class. + /// + /// The parent form + /// The question to be asked, will be the title of the form. + /// The yes button text. + /// A more detailed question text to be displayed in the form itself. If null, then will be used. + /// + /// If or is null + /// + public FormMessage(Form parent, string message, string acceptButtonText = "OK", string messageBodyText = null) + { + // Check arguments + if (string.IsNullOrEmpty(message)) + { + throw new ArgumentNullException(nameof(message) + " must not be null or empty"); + } + if (string.IsNullOrEmpty(acceptButtonText)) + { + throw new ArgumentNullException(nameof(acceptButtonText) + " must not be null or empty"); + } + + // Build the form + InitializeComponent(); + + // Set texts + Text = message; + lbl_Message.Text = messageBodyText ?? message; + btn_Accept.Text = acceptButtonText; + + // Get border sizes + Rectangle screenRectangle = RectangleToScreen(ClientRectangle); + int titleHeight = screenRectangle.Top - Top; + int borderWidth = screenRectangle.Left - Left; + + // Spacing between controls and also between controls and window border + const int MARGIN = 13; + + lbl_Message.Location = new Point(MARGIN, MARGIN); + + int width = Math.Max(btn_Accept.Width, lbl_Message.Width) + (MARGIN * 2) + (borderWidth * 2); + int height = borderWidth + titleHeight + lbl_Message.Top + lbl_Message.Height + MARGIN + btn_Accept.Height + MARGIN; + + Size = new Size(width, height); + + // button (right) + btn_Accept.Location = new Point(this.Width - (borderWidth * 2) - MARGIN - btn_Accept.Width, lbl_Message.Location.Y + lbl_Message.Height + MARGIN); + + ShowDialog(parent); + } + + private void Btn_Accept_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/CoordinateConverter/DCS/Tools/FormMessage.resx b/CoordinateConverter/DCS/Tools/FormMessage.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CoordinateConverter/DCS/Tools/FormMessage.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CoordinateConverter/DCS/Tools/FormStartingWaypoint.cs b/CoordinateConverter/DCS/Tools/FormStartingWaypoint.cs index 90a69aa..e0deadd 100644 --- a/CoordinateConverter/DCS/Tools/FormStartingWaypoint.cs +++ b/CoordinateConverter/DCS/Tools/FormStartingWaypoint.cs @@ -19,7 +19,7 @@ public partial class FormStartingWaypoint : Form /// /// Initializes a new instance of the class. /// - public FormStartingWaypoint(int minSteerPoint, int maxSteerPoint, int defaultValue) + public FormStartingWaypoint(Form parent, int minSteerPoint, int maxSteerPoint, int defaultValue) { InitializeComponent(); if (minSteerPoint > defaultValue || minSteerPoint > maxSteerPoint || maxSteerPoint < defaultValue) @@ -30,6 +30,8 @@ public FormStartingWaypoint(int minSteerPoint, int maxSteerPoint, int defaultVal nud_PointNumber.Minimum = minSteerPoint; nud_PointNumber.Maximum = maxSteerPoint; nud_PointNumber.Value = defaultValue; + + ShowDialog(parent); } private void Btn_OK_Click(object sender, EventArgs e) diff --git a/CoordinateConverter/DCS/Tools/FormUnitImporter.cs b/CoordinateConverter/DCS/Tools/FormUnitImporter.cs index 0b45091..187cc4a 100644 --- a/CoordinateConverter/DCS/Tools/FormUnitImporter.cs +++ b/CoordinateConverter/DCS/Tools/FormUnitImporter.cs @@ -119,7 +119,7 @@ private void Btn_Import_Click(object sender, EventArgs e) Close(); } - private Bullseye GetRefpointBullseye() + private Bullseye GetRefPointBullseye() { int refPointId = ComboItem.GetSelectedValue(cb_RadiusCenter); CoordinateDataEntry refPoint; @@ -274,7 +274,7 @@ private void PopulateCurrentView() currentView.Rows.Clear(); // Delete all data - Bullseye be = GetRefpointBullseye(); + Bullseye be = GetRefPointBullseye(); foreach (DCSUnit unit in allDCSUnits) { CoordinateSharp.Coordinate coordinate = new CoordinateSharp.Coordinate(unit.Coordinate.Lat, unit.Coordinate.Lon); @@ -301,6 +301,7 @@ private void PopulateCurrentView() /// /// Initializes a new instance of the class. /// + /// The reference points. public FormUnitImporter(List referencePoints) { InitializeComponent(); @@ -431,7 +432,7 @@ private void Dgv_Units_ColumnHeaderMouseClick(object sender, DataGridViewCellMou dgv_Units.SortedColumn.HeaderCell.SortGlyphDirection = SortOrder.None; } - var direction = System.ComponentModel.ListSortDirection.Descending; + System.ComponentModel.ListSortDirection direction; if (dgv_Units.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == SortOrder.Ascending) { direction = System.ComponentModel.ListSortDirection.Descending; diff --git a/CoordinateConverter/MainForm.cs b/CoordinateConverter/MainForm.cs index 9a5c58e..a850b48 100644 --- a/CoordinateConverter/MainForm.cs +++ b/CoordinateConverter/MainForm.cs @@ -19,7 +19,7 @@ namespace CoordinateConverter /// public partial class MainForm : Form { - private readonly GitHub.Version VERSION = new GitHub.Version(0, 5, 9); + private readonly GitHub.Version VERSION = new GitHub.Version(0, 5, 10); private readonly Color ERROR_COLOR = Color.Pink; private readonly Color DCS_ERROR_COLOR = Color.Yellow; @@ -1474,8 +1474,8 @@ private void Dgv_CoordinateList_CellContentClick(object objSender, DataGridViewC if (sender.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex < 0) { // a button column header was clicked, the only button in the grid is the delete button - DialogResult answer = MessageBox.Show("Delete all points?", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); - if (answer != DialogResult.Yes) + FormAskBinaryQuestion deletePoints = new FormAskBinaryQuestion(this, "Delete?", "Delete", "Keep", "Delete all points?"); + if (!deletePoints.Result) { return; } @@ -1716,8 +1716,8 @@ private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) FileInfo fi = new FileInfo(filePath); if (fi.Exists) { - result = MessageBox.Show("You are about to overwrite this file.", "Overwrite file?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); - if (result != DialogResult.OK) + FormAskBinaryQuestion overwriteFile = new FormAskBinaryQuestion(this, "Overwrite file?", "Overwrite", "Preserve file", "You are about to overwrite this file."); + if (!overwriteFile.Result) { return; } @@ -1957,12 +1957,13 @@ private void Tsmi_AircraftSelection_Click(object objSender, EventArgs e) else if (sender.Name == tsmi_F18.Name) { selectedAircraft = new F18C(); - MessageBox.Show("Make sure PRECISE mode is selected in HSI->Data.\n" + + string message = "Make sure PRECISE mode is selected in HSI->Data.\n" + "Make sure waypoint sequence is not selected before putting in waypoints.\n" + "The next waypoint number and up from the currently selected one will be overwritten\n" + "Make sure aircraft is in L/L Decimal mode (default). Check in HSI -> Data -> Aircraft -> Bottom right\n" + "Make sure no weapon is selected prior to entering weapon data\n" + - "Maximum number SLAM-ER of steer points is 5.", "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information); + "Maximum number SLAM-ER of steer points is 5."; + FormMessage reminder = new FormMessage(this, "Reminder", "OK", message); } else if (sender.Name == tsmi_F16.Name) { @@ -2355,8 +2356,7 @@ private void StopTransferControl_Click(object sender, EventArgs e) private void Tsmi_AH64_ClearPoints_Click(object sender, EventArgs e) { - FormAH64PointDeleter pointDeleter = new FormAH64PointDeleter(selectedAircraft as AH64); - pointDeleter.ShowDialog(this); + FormAH64PointDeleter pointDeleter = new FormAH64PointDeleter(this, selectedAircraft as AH64); if (pointDeleter.NumberOfCommands > 0) { lock (lockObjProgressBar) @@ -2369,16 +2369,14 @@ private void Tsmi_AH64_ClearPoints_Click(object sender, EventArgs e) private void Tsmi_F16_SetFirstPoint_Click(object sender, EventArgs e) { - FormStartingWaypoint startingWaypointForm = new FormStartingWaypoint(1, 699, 200); - startingWaypointForm.ShowDialog(); + FormStartingWaypoint startingWaypointForm = new FormStartingWaypoint(this, 1, 699, 200); int startingWaypoint = startingWaypointForm.StartingWaypoint; selectedAircraft = new F16C(startingWaypoint); } private void Tsmi_JF17_SetFirstPoint_Click(object sender, EventArgs e) { - FormStartingWaypoint startingWaypointForm = new FormStartingWaypoint(1, 29, 10); - startingWaypointForm.ShowDialog(); + FormStartingWaypoint startingWaypointForm = new FormStartingWaypoint(this, 1, 29, 10); int startingWaypoint = startingWaypointForm.StartingWaypoint; selectedAircraft = new JF17(startingWaypoint); } @@ -2758,7 +2756,7 @@ private void Tsmi_CheckForUpdates_Click(object sender, EventArgs e) else { string message = string.Format("You are using the latest version.\nYour version: {0}\nLatest version: {1}", VERSION.ToString(), latest.ToString()); - MessageBox.Show(message, "Up to date!", MessageBoxButtons.OK, MessageBoxIcon.Information); + new FormMessage(this, "Up to date!", "OK", message).Dispose(); } } }