Skip to content

Commit

Permalink
- Adds FormMessage to replace MessageBox
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
FalcoGer committed Sep 30, 2023
1 parent b8211fc commit d75b2b1
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CoordinateConverter/CoordinateConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<Compile Include="DCS\Tools\FormUnitImporter.Designer.cs">
<DependentUpon>FormUnitImporter.cs</DependentUpon>
</Compile>
<Compile Include="DCS\Tools\FormMessage.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="DCS\Tools\FormMessage.Designer.cs">
<DependentUpon>FormMessage.cs</DependentUpon>
</Compile>
<Compile Include="GitHub\GitHubRelease.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
Expand All @@ -133,6 +139,9 @@
<EmbeddedResource Include="DCS\Tools\FormAskBinaryQuestion.resx">
<DependentUpon>FormAskBinaryQuestion.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DCS\Tools\FormMessage.resx">
<DependentUpon>FormMessage.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DCS\Tools\FormStartingWaypoint.resx">
<DependentUpon>FormStartingWaypoint.cs</DependentUpon>
</EmbeddedResource>
Expand Down
4 changes: 3 additions & 1 deletion CoordinateConverter/DCS/Tools/FormAH64PointDeleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class FormAH64PointDeleter : Form
/// <summary>
/// Initializes a new instance of the <see cref="FormAH64PointDeleter"/> class.
/// </summary>
public FormAH64PointDeleter(AH64 selectedAircraft)
public FormAH64PointDeleter(Form parent, AH64 selectedAircraft)
{
InitializeComponent();
cb_PointType.Items.Clear();
Expand All @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions CoordinateConverter/DCS/Tools/FormAskBinaryQuestion.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
78 changes: 78 additions & 0 deletions CoordinateConverter/DCS/Tools/FormMessage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions CoordinateConverter/DCS/Tools/FormMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace CoordinateConverter.DCS.Tools
{
/// <summary>
/// A form to display a simple message to the user
/// </summary>
/// <seealso cref="System.Windows.Forms.Form" />
public partial class FormMessage : Form
{

/// <summary>
/// Initializes a new instance of the <see cref="FormAskBinaryQuestion"/> class.
/// </summary>
/// <param name="parent">The parent form</param>
/// <param name="message">The question to be asked, will be the title of the form.</param>
/// <param name="acceptButtonText">The yes button text.</param>
/// <param name="messageBodyText">A more detailed question text to be displayed in the form itself. If <c>null</c>, then <paramref name="message"/> will be used.</param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="message"/> or <paramref name="acceptButtonText"/> is null
/// </exception>
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();
}
}
}
120 changes: 120 additions & 0 deletions CoordinateConverter/DCS/Tools/FormMessage.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
4 changes: 3 additions & 1 deletion CoordinateConverter/DCS/Tools/FormStartingWaypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class FormStartingWaypoint : Form
/// <summary>
/// Initializes a new instance of the <see cref="FormStartingWaypoint"/> class.
/// </summary>
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)
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions CoordinateConverter/DCS/Tools/FormUnitImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void Btn_Import_Click(object sender, EventArgs e)
Close();
}

private Bullseye GetRefpointBullseye()
private Bullseye GetRefPointBullseye()
{
int refPointId = ComboItem<int>.GetSelectedValue(cb_RadiusCenter);
CoordinateDataEntry refPoint;
Expand Down Expand Up @@ -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);
Expand All @@ -301,6 +301,7 @@ private void PopulateCurrentView()
/// <summary>
/// Initializes a new instance of the <see cref="FormUnitImporter"/> class.
/// </summary>
/// <param name="referencePoints">The reference points.</param>
public FormUnitImporter(List<CoordinateDataEntry> referencePoints)
{
InitializeComponent();
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit d75b2b1

Please sign in to comment.