some improvements

This commit is contained in:
2024-06-10 13:04:53 +02:00
parent 3cd0f8dce8
commit df8266fc40
18 changed files with 565 additions and 92 deletions

View File

@@ -0,0 +1,76 @@
namespace Pilz.UI.Dialogs;
partial class DialogBase
{
public delegate void DialogLoadingEventHandler(DialogLoadingEventArgs e);
public delegate void DialogClosedEventHandler(DialogClosedEventArgs e);
public static event DialogLoadingEventHandler? DialogLoading;
public static event DialogClosedEventHandler? DialogClosed;
public static T Show<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return Show<T>(null, title, icon, tag);
}
public static T ShowDialog<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog<T>(null, title, icon, tag);
}
public static T Show<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return Show(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T ShowDialog<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T Show<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return Show(dialogPanel, null, title, icon);
}
public static T ShowDialog<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return ShowDialog(dialogPanel, null, title, icon);
}
public static T Show<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).Show();
return dialogPanel;
}
public static T ShowDialog<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).ShowDialog();
return dialogPanel;
}
private static T CreatePanelInstance<T>(object? tag) where T : FlyoutBase
{
T dialogPanel = Activator.CreateInstance<T>();
dialogPanel.Tag = tag;
return dialogPanel;
}
private static DialogBase CreateForm<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
dialogPanel.Dock = DockStyle.Fill;
var dialog = new DialogBase(dialogPanel)
{
Text = title,
Icon = icon,
StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent,
ClientSize = dialogPanel.Size
};
dialog.Controls.Add(dialogPanel);
return dialog;
}
}

View File

@@ -0,0 +1,30 @@
namespace Pilz.UI.Dialogs;
public partial class DialogBase : Form
{
public FlyoutBase? DialogPanel { get; private set; }
private DialogBase()
{
Load += DialogBaseForm_Load;
FormClosed += DialogBaseForm_FormClosed;
}
public DialogBase(FlyoutBase? dialogPanel) : this()
{
DialogPanel = dialogPanel;
}
private void DialogBaseForm_Load(object? sender, EventArgs e)
{
if (DialogPanel is ILoadContent iLoadContent)
iLoadContent.LoadContent();
DialogLoading?.Invoke(new DialogLoadingEventArgs(this));
}
private void DialogBaseForm_FormClosed(object? sender, FormClosedEventArgs e)
{
DialogClosed?.Invoke(new DialogClosedEventArgs(this));
}
}

View File

@@ -0,0 +1,7 @@
namespace Pilz.UI.Dialogs;
public class DialogClosedEventArgs(DialogBase dialog) : EventArgs
{
public DialogBase Parent { get; } = dialog;
public FlyoutBase? Content => Parent?.DialogPanel;
}

View File

@@ -0,0 +1,7 @@
namespace Pilz.UI.Dialogs;
public class DialogLoadingEventArgs(DialogBase dialog) : EventArgs
{
public DialogBase Parent { get; } = dialog;
public FlyoutBase? Content => Parent?.DialogPanel;
}

121
Pilz.UI/Dialogs/FlyoutBase.Designer.cs generated Normal file
View File

@@ -0,0 +1,121 @@
namespace Pilz.UI.Dialogs;
partial class FlyoutBase
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
tableLayoutPanel_TitlePanel = new System.Windows.Forms.TableLayoutPanel();
label_Title = new System.Windows.Forms.Label();
tableLayoutPanel_ActionPanel = new System.Windows.Forms.TableLayoutPanel();
button_Accept = new System.Windows.Forms.Button();
button_Cancel = new System.Windows.Forms.Button();
tableLayoutPanel_TitlePanel.SuspendLayout();
tableLayoutPanel_ActionPanel.SuspendLayout();
SuspendLayout();
//
// tableLayoutPanel_TitlePanel
//
tableLayoutPanel_TitlePanel.ColumnCount = 1;
tableLayoutPanel_TitlePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
tableLayoutPanel_TitlePanel.Controls.Add(label_Title, 0, 0);
tableLayoutPanel_TitlePanel.Dock = System.Windows.Forms.DockStyle.Top;
tableLayoutPanel_TitlePanel.Location = new System.Drawing.Point(0, 0);
tableLayoutPanel_TitlePanel.Name = "tableLayoutPanel_TitlePanel";
tableLayoutPanel_TitlePanel.RowCount = 1;
tableLayoutPanel_TitlePanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
tableLayoutPanel_TitlePanel.Size = new System.Drawing.Size(300, 29);
tableLayoutPanel_TitlePanel.TabIndex = 0;
//
// label_Title
//
label_Title.Dock = System.Windows.Forms.DockStyle.Fill;
label_Title.Location = new System.Drawing.Point(3, 0);
label_Title.Name = "label_Title";
label_Title.Size = new System.Drawing.Size(294, 29);
label_Title.TabIndex = 0;
label_Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// tableLayoutPanel_ActionPanel
//
tableLayoutPanel_ActionPanel.AutoSize = true;
tableLayoutPanel_ActionPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
tableLayoutPanel_ActionPanel.ColumnCount = 3;
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
tableLayoutPanel_ActionPanel.Controls.Add(button_Cancel, 2, 0);
tableLayoutPanel_ActionPanel.Controls.Add(button_Accept, 1, 0);
tableLayoutPanel_ActionPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
tableLayoutPanel_ActionPanel.Location = new System.Drawing.Point(0, 121);
tableLayoutPanel_ActionPanel.Name = "tableLayoutPanel_ActionPanel";
tableLayoutPanel_ActionPanel.RowCount = 1;
tableLayoutPanel_ActionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
tableLayoutPanel_ActionPanel.Size = new System.Drawing.Size(300, 29);
tableLayoutPanel_ActionPanel.TabIndex = 1;
//
// button_Accept
//
button_Accept.Location = new System.Drawing.Point(141, 3);
button_Accept.Name = "button_Accept";
button_Accept.Size = new System.Drawing.Size(75, 23);
button_Accept.TabIndex = 2;
button_Accept.Text = "Accept";
button_Accept.UseVisualStyleBackColor = true;
button_Accept.Click += Button_Accept_Click;
//
// button_Cancel
//
button_Cancel.Location = new System.Drawing.Point(222, 3);
button_Cancel.Name = "button_Cancel";
button_Cancel.Size = new System.Drawing.Size(75, 23);
button_Cancel.TabIndex = 3;
button_Cancel.Text = "Cancel";
button_Cancel.UseVisualStyleBackColor = true;
button_Cancel.Click += Button_Cancel_Click;
//
// FlyoutBase
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
Controls.Add(tableLayoutPanel_ActionPanel);
Controls.Add(tableLayoutPanel_TitlePanel);
Name = "FlyoutBase";
Size = new System.Drawing.Size(300, 150);
tableLayoutPanel_TitlePanel.ResumeLayout(false);
tableLayoutPanel_ActionPanel.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel_TitlePanel;
private System.Windows.Forms.Label label_Title;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel_ActionPanel;
private System.Windows.Forms.Button button_Cancel;
private System.Windows.Forms.Button button_Accept;
}

View File

@@ -0,0 +1,89 @@
namespace Pilz.UI.Dialogs;
public partial class FlyoutBase : UserControl
{
public DialogResult Result { get; protected set; }
public bool RegisterDialogAccept { get; set; } = true;
public bool RegisterDialogCancel { get; set; } = false;
protected bool ActionPanelVisible
{
get => tableLayoutPanel_ActionPanel.Visible;
set => tableLayoutPanel_ActionPanel.Visible = value;
}
protected bool CancelButtonVisible
{
get => button_Cancel.Visible;
set => button_Cancel.Visible = value;
}
protected bool CancelButtonEnable
{
get => button_Cancel.Enabled;
set => button_Cancel.Enabled = value;
}
protected bool ConfirmButtonEnable
{
get => button_Accept.Enabled;
set => button_Accept.Enabled = value;
}
public string Title
{
get => label_Title.Text;
set
{
label_Title.Text = value;
SetShowTitlePanel();
}
}
public FlyoutBase()
{
InitializeComponent();
ParentChanged += FlyoutBase_ParentChanged; ;
}
private void FlyoutBase_ParentChanged(object sender, System.EventArgs e)
{
var frm = FindForm();
if (frm != null)
{
if (RegisterDialogAccept)
frm.AcceptButton = button_Accept;
if (RegisterDialogCancel)
frm.CancelButton = button_Cancel;
}
}
protected void Close(DialogResult result)
{
Result = result;
if (FindForm() is DialogBase dialogForm)
dialogForm.Close();
}
protected virtual bool ValidateOK()
{
return true;
}
private void SetShowTitlePanel()
{
tableLayoutPanel_TitlePanel.Visible = !string.IsNullOrWhiteSpace(label_Title.Text);
}
private void Button_Accept_Click(object sender, System.EventArgs e)
{
if (ValidateOK())
Close(DialogResult.OK);
}
private void Button_Cancel_Click(object sender, System.EventArgs e)
{
Close(DialogResult.Cancel);
}
}

View File

@@ -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>

View File

@@ -0,0 +1,6 @@
namespace Pilz.UI.Dialogs;
public interface ILoadContent
{
void LoadContent();
}