add ability to show DialogBaseForm with custom created content

This commit is contained in:
2023-10-19 11:47:03 +02:00
parent 4a4398ed84
commit 45ce141d9e
2 changed files with 33 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Pilz.UI.Telerik.Dialogs namespace Pilz.UI.Telerik.Dialogs
{ {
@@ -19,26 +20,36 @@ namespace Pilz.UI.Telerik.Dialogs
public static T ShowDialog<T>(string title, Icon icon, object? tag = null) where T : FlyoutDialogBase public static T ShowDialog<T>(string title, Icon icon, object? tag = null) where T : FlyoutDialogBase
{ {
return ShowDialog<T>(null, title, icon, tag); return ShowDialog<T>(null, title, icon, tag);
} }
public static T ShowDialog<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutDialogBase public static T ShowDialog<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutDialogBase
{ {
var dialogPanel = Activator.CreateInstance<T>(); T dialogPanel = Activator.CreateInstance<T>();
dialogPanel.Dock = DockStyle.Fill; dialogPanel.Tag = tag;
dialogPanel.Tag = tag; return ShowDialog(dialogPanel, parent, title, icon);
}
var dialog = new DialogBaseForm public static T ShowDialog<T>(T dialogPanel, string title, Icon icon) where T : FlyoutDialogBase
{ {
DialogPanel = dialogPanel, return ShowDialog(dialogPanel, null, title, icon);
Text = title, }
Icon = icon,
StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent,
ClientSize = dialogPanel.Size
};
dialog.Controls.Add(dialogPanel);
dialog.ShowDialog(parent);
return dialogPanel; public static T ShowDialog<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T: FlyoutDialogBase
} {
dialogPanel.Dock = DockStyle.Fill;
var dialog = new DialogBaseForm(dialogPanel)
{
Text = title,
Icon = icon,
StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent,
ClientSize = dialogPanel.Size
};
dialog.Controls.Add(dialogPanel);
dialog.ShowDialog(parent);
return dialogPanel;
}
} }
} }

View File

@@ -18,6 +18,11 @@ namespace Pilz.UI.Telerik.Dialogs
FormClosed += DialogBaseForm_FormClosed; FormClosed += DialogBaseForm_FormClosed;
} }
public DialogBaseForm(FlyoutDialogBase? dialogPanel) : this()
{
DialogPanel = dialogPanel;
}
private void DialogBaseForm_Load(object? sender, EventArgs e) private void DialogBaseForm_Load(object? sender, EventArgs e)
{ {
if (DialogPanel is ILoadContent iLoadContent) if (DialogPanel is ILoadContent iLoadContent)