From ea638664812b57311687561c4550670a0506c3e0 Mon Sep 17 00:00:00 2001 From: Schedel Pascal Date: Thu, 13 Jun 2024 08:07:15 +0200 Subject: [PATCH] small improvements to RadFlyoutBase & RadDialogBase --- .../Dialogs/RadDialogBase.Statics.cs | 29 ++++++++++++------- .../Dialogs/RadFlyoutBase.Statics.cs | 24 +++++++++++++-- .../Extensions.cs | 3 +- 3 files changed, 40 insertions(+), 16 deletions(-) rename {Pilz.UI.Telerik.SymbolFactory => Pilz.UI.Telerik}/Extensions.cs (88%) diff --git a/Pilz.UI.Telerik/Dialogs/RadDialogBase.Statics.cs b/Pilz.UI.Telerik/Dialogs/RadDialogBase.Statics.cs index 3e021ba..5a4a0ff 100644 --- a/Pilz.UI.Telerik/Dialogs/RadDialogBase.Statics.cs +++ b/Pilz.UI.Telerik/Dialogs/RadDialogBase.Statics.cs @@ -1,4 +1,6 @@ -namespace Pilz.UI.Telerik.Dialogs; +using Telerik.WinControls; + +namespace Pilz.UI.Telerik.Dialogs; partial class RadDialogBase { @@ -8,43 +10,43 @@ partial class RadDialogBase public static event DialogLoadingEventHandler? DialogLoading; public static event DialogClosedEventHandler? DialogClosed; - public static T Show(string title, Icon icon, object? tag = null) where T : RadFlyoutBase + public static T Show(string? title, object? icon, object? tag = null) where T : RadFlyoutBase { return Show(null, title, icon, tag); } - public static T ShowDialog(string title, Icon icon, object? tag = null) where T : RadFlyoutBase + public static T ShowDialog(string? title, object? icon, object? tag = null) where T : RadFlyoutBase { return ShowDialog(null, title, icon, tag); } - public static T Show(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : RadFlyoutBase + public static T Show(IWin32Window? parent, string? title, object? icon, object? tag = null) where T : RadFlyoutBase { return Show(CreatePanelInstance(tag), parent, title, icon); } - public static T ShowDialog(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : RadFlyoutBase + public static T ShowDialog(IWin32Window? parent, string? title, object? icon, object? tag = null) where T : RadFlyoutBase { return ShowDialog(CreatePanelInstance(tag), parent, title, icon); } - public static T Show(T dialogPanel, string title, Icon icon) where T : RadFlyoutBase + public static T Show(T dialogPanel, string? title, object? icon) where T : RadFlyoutBase { return Show(dialogPanel, null, title, icon); } - public static T ShowDialog(T dialogPanel, string title, Icon icon) where T : RadFlyoutBase + public static T ShowDialog(T dialogPanel, string? title, object? icon) where T : RadFlyoutBase { return ShowDialog(dialogPanel, null, title, icon); } - public static T Show(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : RadFlyoutBase + public static T Show(T dialogPanel, IWin32Window? parent, string? title, object? icon) where T : RadFlyoutBase { CreateForm(dialogPanel, parent, title, icon).Show(); return dialogPanel; } - public static T ShowDialog(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : RadFlyoutBase + public static T ShowDialog(T dialogPanel, IWin32Window? parent, string? title, object? icon) where T : RadFlyoutBase { CreateForm(dialogPanel, parent, title, icon).ShowDialog(); return dialogPanel; @@ -57,14 +59,19 @@ partial class RadDialogBase return dialogPanel; } - private static RadDialogBase CreateForm(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : RadFlyoutBase + private static RadDialogBase CreateForm(T dialogPanel, IWin32Window? parent, string? title, object? icon) where T : RadFlyoutBase { dialogPanel.Dock = DockStyle.Fill; + if (icon is RadSvgImage svg) + icon = svg.ToImage(); + if (icon is Image img) + icon = img.ToIcon(); + var dialog = new RadDialogBase(dialogPanel) { Text = title, - Icon = icon, + Icon = icon as Icon, StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent, ClientSize = dialogPanel.Size }; diff --git a/Pilz.UI.Telerik/Dialogs/RadFlyoutBase.Statics.cs b/Pilz.UI.Telerik/Dialogs/RadFlyoutBase.Statics.cs index f78940b..ade4029 100644 --- a/Pilz.UI.Telerik/Dialogs/RadFlyoutBase.Statics.cs +++ b/Pilz.UI.Telerik/Dialogs/RadFlyoutBase.Statics.cs @@ -1,4 +1,6 @@ -using Telerik.WinControls.UI; +using Telerik.WinControls; +using Telerik.WinControls.Svg; +using Telerik.WinControls.UI; using Telerik.WinControls.UI.SplashScreen; namespace Pilz.UI.Telerik.Dialogs; @@ -24,6 +26,9 @@ partial class RadFlyoutBase private static readonly List flyoutCloseHandlers = new(); private static object? tagToAssign = null; + private static string? titleToAssing = null; + private static RadSvgImage? iconToAssign = null; + public static Control? ParentContext { get; private set; } = null; static RadFlyoutBase() @@ -39,6 +44,12 @@ partial class RadFlyoutBase if (tagToAssign != null) dialogBase.Tag = tagToAssign; + if (titleToAssing != null) + dialogBase.Title = titleToAssing; + + if (iconToAssign != null) + dialogBase.TitleIcon = iconToAssign; + var eventArgs = new FlyoutCreatedEventArgs(dialogBase); if (dialogBase is ILoadContent iLoadContent) @@ -74,12 +85,19 @@ partial class RadFlyoutBase public static void Show(Control controlToAssociate, object? tag = null) { - Show(controlToAssociate, typeof(T), tag); + Show(controlToAssociate, tag: tag); } - public static void Show(Control controlToAssociate, Type flyoutContentType, object? tag = null) + public static void Show(Control controlToAssociate, string? title, RadSvgImage? icon, object? tag = null) + { + Show(controlToAssociate, typeof(T), title, icon, tag: tag); + } + + public static void Show(Control controlToAssociate, Type flyoutContentType, string? title, RadSvgImage? icon, object? tag = null) { tagToAssign = tag; + titleToAssing = title; + iconToAssign = icon; ParentContext = controlToAssociate; RadFlyoutManager.Show(controlToAssociate, flyoutContentType); } diff --git a/Pilz.UI.Telerik.SymbolFactory/Extensions.cs b/Pilz.UI.Telerik/Extensions.cs similarity index 88% rename from Pilz.UI.Telerik.SymbolFactory/Extensions.cs rename to Pilz.UI.Telerik/Extensions.cs index fd8fe55..99894a9 100644 --- a/Pilz.UI.Telerik.SymbolFactory/Extensions.cs +++ b/Pilz.UI.Telerik/Extensions.cs @@ -1,5 +1,4 @@ -using System.Drawing; -using Telerik.WinControls; +using Telerik.WinControls; using Telerik.WinControls.Svg; namespace Pilz.UI.Telerik;