change UI to UI.WinForms
This commit is contained in:
78
Pilz.UI.WinForms/Dialogs/DialogBase.Statics.cs
Normal file
78
Pilz.UI.WinForms/Dialogs/DialogBase.Statics.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Pilz.UI.WinForms.Dialogs;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
35
Pilz.UI.WinForms/Dialogs/DialogBase.cs
Normal file
35
Pilz.UI.WinForms/Dialogs/DialogBase.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Pilz.UI.WinForms;
|
||||
using Pilz.UI.WinForms.Dialogs;
|
||||
|
||||
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();
|
||||
else if (DialogPanel is ILoadContentAsync iLoadContentAsync)
|
||||
Task.Run(iLoadContentAsync.LoadContentAsync).Wait();
|
||||
|
||||
DialogLoading?.Invoke(new DialogLoadingEventArgs(this));
|
||||
}
|
||||
|
||||
private void DialogBaseForm_FormClosed(object? sender, FormClosedEventArgs e)
|
||||
{
|
||||
DialogClosed?.Invoke(new DialogClosedEventArgs(this));
|
||||
}
|
||||
}
|
||||
9
Pilz.UI.WinForms/Dialogs/DialogClosedEventArgs.cs
Normal file
9
Pilz.UI.WinForms/Dialogs/DialogClosedEventArgs.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Pilz.UI.Dialogs;
|
||||
|
||||
namespace Pilz.UI.WinForms.Dialogs;
|
||||
|
||||
public class DialogClosedEventArgs(DialogBase dialog) : EventArgs
|
||||
{
|
||||
public DialogBase Parent { get; } = dialog;
|
||||
public FlyoutBase? Content => Parent?.DialogPanel;
|
||||
}
|
||||
9
Pilz.UI.WinForms/Dialogs/DialogLoadingEventArgs.cs
Normal file
9
Pilz.UI.WinForms/Dialogs/DialogLoadingEventArgs.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Pilz.UI.Dialogs;
|
||||
|
||||
namespace Pilz.UI.WinForms.Dialogs;
|
||||
|
||||
public class DialogLoadingEventArgs(DialogBase dialog) : EventArgs
|
||||
{
|
||||
public DialogBase Parent { get; } = dialog;
|
||||
public FlyoutBase? Content => Parent?.DialogPanel;
|
||||
}
|
||||
223
Pilz.UI.WinForms/Dialogs/FlyoutBase.cs
Normal file
223
Pilz.UI.WinForms/Dialogs/FlyoutBase.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
using Pilz.UI.Dialogs;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Pilz.UI.WinForms.Dialogs;
|
||||
|
||||
public partial class FlyoutBase : UserControl
|
||||
{
|
||||
private bool addedControlsToUi;
|
||||
|
||||
protected TableLayoutPanel tableLayoutPanel_TitlePanel;
|
||||
protected Label label_Title;
|
||||
protected TableLayoutPanel tableLayoutPanel_ActionPanel;
|
||||
protected Button button_Cancel;
|
||||
protected Button button_Accept;
|
||||
|
||||
[ReadOnly(true)]
|
||||
public DialogResult Result { get; protected set; }
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool RegisterDialogAccept { get; set; } = true;
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool RegisterDialogCancel { get; set; } = true;
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool ActionPanelVisible
|
||||
{
|
||||
get => tableLayoutPanel_ActionPanel.Visible;
|
||||
set => tableLayoutPanel_ActionPanel.Visible = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool CancelButtonVisible
|
||||
{
|
||||
get => button_Cancel.Visible;
|
||||
set => button_Cancel.Visible = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool CancelButtonEnable
|
||||
{
|
||||
get => button_Cancel.Enabled;
|
||||
set => button_Cancel.Enabled = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool ConfirmButtonEnable
|
||||
{
|
||||
get => button_Accept.Enabled;
|
||||
set => button_Accept.Enabled = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("Okay")]
|
||||
public string ConfirmButtonText
|
||||
{
|
||||
get => button_Accept.Text;
|
||||
set => button_Accept.Text = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("Cancel")]
|
||||
public string CancelButtonText
|
||||
{
|
||||
get => button_Cancel.Text;
|
||||
set => button_Cancel.Text = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("")]
|
||||
public string Title
|
||||
{
|
||||
get => label_Title.Text;
|
||||
set
|
||||
{
|
||||
label_Title.Text = value;
|
||||
SetShowTitlePanel();
|
||||
}
|
||||
}
|
||||
|
||||
public FlyoutBase()
|
||||
{
|
||||
InitializeComponent();
|
||||
ParentChanged += FlyoutBase_ParentChanged;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// button_Accept
|
||||
button_Accept = new Button
|
||||
{
|
||||
Name = "button_Accept",
|
||||
Size = new Size(75, 23),
|
||||
TabIndex = int.MaxValue - 1,
|
||||
Text = "Accept",
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
button_Accept.Click += Button_Accept_Click;
|
||||
|
||||
// button_Cancel
|
||||
button_Cancel = new Button
|
||||
{
|
||||
Name = "button_Cancel",
|
||||
Size = new Size(75, 23),
|
||||
TabIndex = int.MaxValue,
|
||||
Text = "Cancel",
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
button_Cancel.Click += Button_Cancel_Click;
|
||||
|
||||
// label_Title
|
||||
label_Title = new Label
|
||||
{
|
||||
Name = "label_Title",
|
||||
Dock = DockStyle.Fill,
|
||||
TextAlign = ContentAlignment.MiddleLeft
|
||||
};
|
||||
|
||||
// tableLayoutPanel_TitlePanel
|
||||
tableLayoutPanel_TitlePanel = new TableLayoutPanel
|
||||
{
|
||||
Name = "tableLayoutPanel_TitlePanel",
|
||||
Dock = DockStyle.Top,
|
||||
Size = new Size(ClientSize.Width, 29),
|
||||
Visible = false,
|
||||
ColumnCount = 1,
|
||||
RowCount = 1
|
||||
};
|
||||
tableLayoutPanel_TitlePanel.SuspendLayout();
|
||||
tableLayoutPanel_TitlePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel_TitlePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel_TitlePanel.Controls.Add(label_Title, 0, 0);
|
||||
|
||||
// tableLayoutPanel_ActionPanel
|
||||
tableLayoutPanel_ActionPanel = new TableLayoutPanel
|
||||
{
|
||||
Name = "tableLayoutPanel_ActionPanel",
|
||||
AutoSize = true,
|
||||
AutoSizeMode = AutoSizeMode.GrowAndShrink,
|
||||
Dock = DockStyle.Bottom,
|
||||
Size = new Size(ClientSize.Width, 29),
|
||||
ColumnCount = 3,
|
||||
RowCount = 1
|
||||
};
|
||||
tableLayoutPanel_ActionPanel.SuspendLayout();
|
||||
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
||||
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle());
|
||||
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle());
|
||||
tableLayoutPanel_ActionPanel.RowStyles.Add(new RowStyle());
|
||||
tableLayoutPanel_ActionPanel.Controls.Add(button_Cancel, 2, 0);
|
||||
tableLayoutPanel_ActionPanel.Controls.Add(button_Accept, 1, 0);
|
||||
|
||||
// FlyoutBase
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Size = new Size(300, 150);
|
||||
|
||||
tableLayoutPanel_TitlePanel.ResumeLayout(false);
|
||||
tableLayoutPanel_ActionPanel.ResumeLayout(false);
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
if (!addedControlsToUi && !DesignMode)
|
||||
{
|
||||
SuspendLayout();
|
||||
Controls.Add(tableLayoutPanel_ActionPanel);
|
||||
tableLayoutPanel_ActionPanel.SendToBack();
|
||||
Controls.Add(tableLayoutPanel_TitlePanel);
|
||||
tableLayoutPanel_TitlePanel.SendToBack();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
addedControlsToUi = true;
|
||||
}
|
||||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
private void FlyoutBase_ParentChanged(object sender, EventArgs e)
|
||||
{
|
||||
var frm = FindForm();
|
||||
if (frm != null)
|
||||
{
|
||||
if (RegisterDialogAccept)
|
||||
frm.AcceptButton = button_Accept;
|
||||
|
||||
if (RegisterDialogCancel)
|
||||
{
|
||||
frm.CancelButton = button_Cancel;
|
||||
button_Cancel.DialogResult = DialogResult.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Close(DialogResult result)
|
||||
{
|
||||
Result = result;
|
||||
|
||||
if (FindForm() is DialogBase dialogForm)
|
||||
dialogForm.Close();
|
||||
}
|
||||
|
||||
protected virtual bool ValidateOK()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void SetShowTitlePanel()
|
||||
{
|
||||
tableLayoutPanel_TitlePanel.Visible = !string.IsNullOrWhiteSpace(label_Title.Text);
|
||||
}
|
||||
|
||||
protected virtual void Button_Accept_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ValidateOK())
|
||||
Close(DialogResult.OK);
|
||||
}
|
||||
|
||||
protected virtual void Button_Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close(DialogResult.Cancel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user