Added the input dialog

This commit is contained in:
Thorsten Sommer 2022-07-09 15:07:07 +02:00
parent 4ef0d91510
commit 5d09cb7e57
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 265 additions and 0 deletions

View File

@ -0,0 +1,166 @@
namespace UI_WinForms.Dialogs
{
partial class InputDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayout = new System.Windows.Forms.TableLayoutPanel();
this.labelHead = new System.Windows.Forms.Label();
this.flowLayoutBottom = new System.Windows.Forms.FlowLayoutPanel();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.textBoxInput = new System.Windows.Forms.TextBox();
this.checkBoxIsRoot = new System.Windows.Forms.CheckBox();
this.tableLayout.SuspendLayout();
this.flowLayoutBottom.SuspendLayout();
this.SuspendLayout();
//
// tableLayout
//
this.tableLayout.AutoSize = true;
this.tableLayout.ColumnCount = 1;
this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayout.Controls.Add(this.labelHead, 0, 0);
this.tableLayout.Controls.Add(this.flowLayoutBottom, 0, 2);
this.tableLayout.Controls.Add(this.textBoxInput, 0, 1);
this.tableLayout.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayout.Location = new System.Drawing.Point(0, 0);
this.tableLayout.Name = "tableLayout";
this.tableLayout.RowCount = 4;
this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 66F));
this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayout.Size = new System.Drawing.Size(800, 139);
this.tableLayout.TabIndex = 0;
//
// labelHead
//
this.labelHead.AutoSize = true;
this.labelHead.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelHead.Location = new System.Drawing.Point(3, 0);
this.labelHead.Name = "labelHead";
this.labelHead.Size = new System.Drawing.Size(794, 28);
this.labelHead.TabIndex = 0;
this.labelHead.Text = "header";
//
// flowLayoutBottom
//
this.flowLayoutBottom.Controls.Add(this.buttonOk);
this.flowLayoutBottom.Controls.Add(this.buttonCancel);
this.flowLayoutBottom.Controls.Add(this.checkBoxIsRoot);
this.flowLayoutBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutBottom.Location = new System.Drawing.Point(3, 68);
this.flowLayoutBottom.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.flowLayoutBottom.Name = "flowLayoutBottom";
this.flowLayoutBottom.Size = new System.Drawing.Size(797, 66);
this.flowLayoutBottom.TabIndex = 0;
//
// buttonOk
//
this.buttonOk.AutoSize = true;
this.buttonOk.Image = global::UI_WinForms.Resources.Icons.icons8_ok_512;
this.buttonOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.buttonOk.Location = new System.Drawing.Point(3, 3);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(114, 60);
this.buttonOk.TabIndex = 1;
this.buttonOk.Text = "Ok";
this.buttonOk.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
this.buttonCancel.AutoSize = true;
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Image = global::UI_WinForms.Resources.Icons.icons8_cancel_512;
this.buttonCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.buttonCancel.Location = new System.Drawing.Point(123, 3);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(124, 60);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.buttonCancel.UseVisualStyleBackColor = true;
//
// textBoxInput
//
this.textBoxInput.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxInput.Location = new System.Drawing.Point(6, 31);
this.textBoxInput.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
this.textBoxInput.Name = "textBoxInput";
this.textBoxInput.Size = new System.Drawing.Size(791, 34);
this.textBoxInput.TabIndex = 1;
this.textBoxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxInput_KeyUp);
//
// checkBoxIsRoot
//
this.checkBoxIsRoot.AutoSize = true;
this.checkBoxIsRoot.Dock = System.Windows.Forms.DockStyle.Left;
this.checkBoxIsRoot.Location = new System.Drawing.Point(253, 3);
this.checkBoxIsRoot.Name = "checkBoxIsRoot";
this.checkBoxIsRoot.Size = new System.Drawing.Size(458, 60);
this.checkBoxIsRoot.TabIndex = 3;
this.checkBoxIsRoot.Text = "Add a root node (i.e. ignoring the selected node)";
this.checkBoxIsRoot.UseVisualStyleBackColor = true;
//
// InputDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoSize = true;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(800, 139);
this.Controls.Add(this.tableLayout);
this.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "InputDialog";
this.tableLayout.ResumeLayout(false);
this.tableLayout.PerformLayout();
this.flowLayoutBottom.ResumeLayout(false);
this.flowLayoutBottom.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TableLayoutPanel tableLayout;
private Label labelHead;
private FlowLayoutPanel flowLayoutBottom;
private TextBox textBoxInput;
private Button buttonOk;
private Button buttonCancel;
private CheckBox checkBoxIsRoot;
}
}

View File

@ -0,0 +1,39 @@
namespace UI_WinForms.Dialogs;
public partial class InputDialog : Form
{
private InputDialog()
{
this.InitializeComponent();
}
public static InputResult Show(string message, string title, string placeholder = "", string preloadedText = "", string okButtonText = "Ok", string cancelButtonText = "Cancel")
{
using var inputDialog = new InputDialog();
inputDialog.labelHead.Text = message;
inputDialog.Text = title;
inputDialog.textBoxInput.PlaceholderText = placeholder;
inputDialog.textBoxInput.Text = preloadedText;
inputDialog.buttonOk.Text = okButtonText;
inputDialog.buttonCancel.Text = cancelButtonText;
return new InputResult(inputDialog.ShowDialog(), inputDialog.textBoxInput.Text, inputDialog.checkBoxIsRoot.Checked);
}
private void textBoxInput_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode is Keys.Enter or Keys.Return)
this.buttonOk.PerformClick();
}
private void buttonOk_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(this.textBoxInput.Text))
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
public readonly record struct InputResult(DialogResult DialogResult, string Text, bool IsRoot);
}

View File

@ -0,0 +1,60 @@
<root>
<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>