From 03ad8e790e61cfe0da1958befde1a578780f3ad4 Mon Sep 17 00:00:00 2001 From: Laurence Luo Date: Sat, 14 Sep 2024 15:58:40 +0800 Subject: [PATCH 1/3] Add optional Light Mode to MessageBox and InputBox 1. Add optional Boolean parameter for enabling Dark Mode or Light Mode in MessageBox and InputBox. --- SourceFiles/Messenger.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SourceFiles/Messenger.cs b/SourceFiles/Messenger.cs index d420fea..e8fe51a 100644 --- a/SourceFiles/Messenger.cs +++ b/SourceFiles/Messenger.cs @@ -53,7 +53,7 @@ public static DialogResult MessageBox(Exception ex, bool ShowTrace = true) => /// It is a modal window, blocking other actions in the application until the user closes it. public static DialogResult MessageBox( string Message, string title, MessageBoxButtons buttons = MessageBoxButtons.OK, - MessageBoxIcon icon = MessageBoxIcon.Information) + MessageBoxIcon icon = MessageBoxIcon.Information, bool pIsDarkMode = true) { Debug.WriteLine(icon.ToString()); @@ -74,7 +74,7 @@ public static DialogResult MessageBox( break; } - return MessageBox(Message, title, Icon, buttons); + return MessageBox(Message, title, Icon, buttons, pIsDarkMode); } /// Displays a message window, also known as a dialog box, which presents a message to the user. @@ -85,7 +85,7 @@ public static DialogResult MessageBox( /// It is a modal window, blocking other actions in the application until the user closes it. public static DialogResult MessageBox( string Message, string title, MsgIcon Icon, - MessageBoxButtons buttons = MessageBoxButtons.OK) + MessageBoxButtons buttons = MessageBoxButtons.OK, bool pIsDarkMode = true) { Form form = new Form { @@ -99,6 +99,8 @@ public static DialogResult MessageBox( }; DarkModeCS DMode = new DarkModeCS(form); + DMode.ApplyTheme(pIsDarkMode); + Base64Icons _Icons = new Base64Icons(); #region Bottom Panel & Buttons @@ -320,7 +322,7 @@ public static DialogResult MessageBox( /// OK si el usuario acepta. By BlueMystic @2024 public static DialogResult InputBox( string title, string promptText, ref List Fields, - MsgIcon Icon = 0, MessageBoxButtons buttons = MessageBoxButtons.OK) + MsgIcon Icon = 0, MessageBoxButtons buttons = MessageBoxButtons.OK, bool pIsDarkMode = true) { Form form = new Form { @@ -334,6 +336,7 @@ public static DialogResult InputBox( }; DarkModeCS DMode = new DarkModeCS(form); + DMode.ApplyTheme(pIsDarkMode); // Error Management & Icon Library: ErrorProvider Err = new ErrorProvider(); @@ -521,7 +524,7 @@ public static DialogResult InputBox( #endregion Buttons #region Prompt Text - + Label lblPrompt = new Label { Dock = DockStyle.Top, From ede16ab2ab139fb9eeb9323e217f127fa59b88ca Mon Sep 17 00:00:00 2001 From: Laurence Luo Date: Sat, 14 Sep 2024 16:00:58 +0800 Subject: [PATCH 2/3] Make InputBox's Prompt Text to be optional 1. when setting promptText to empty (""), hide the lblPrompt control. --- SourceFiles/Messenger.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/SourceFiles/Messenger.cs b/SourceFiles/Messenger.cs index e8fe51a..b36f005 100644 --- a/SourceFiles/Messenger.cs +++ b/SourceFiles/Messenger.cs @@ -525,15 +525,21 @@ public static DialogResult InputBox( #region Prompt Text - Label lblPrompt = new Label + Label lblPrompt = new Label(); + if (!string.IsNullOrWhiteSpace(promptText)) { - Dock = DockStyle.Top, - Text = promptText, - //Font = new Font(form.Font, FontStyle.Bold), - AutoSize = false, - Height = 24, - TextAlign = ContentAlignment.MiddleCenter - }; + lblPrompt.Dock = DockStyle.Top; + lblPrompt.Text = promptText; //Font = new Font(form.Font, FontStyle.Bold), + lblPrompt.AutoSize = false; + lblPrompt.Height = 24; + lblPrompt.TextAlign = ContentAlignment.MiddleCenter; + } + else + { + lblPrompt.Location = new Point(0, 0); + lblPrompt.Width = 0; + lblPrompt.Height = 0; + } form.Controls.Add(lblPrompt); #endregion Prompt Text From dcc51d0f32e5466313a73c733ee462ef4bc4526c Mon Sep 17 00:00:00 2001 From: Laurence Luo Date: Sat, 14 Sep 2024 17:02:06 +0800 Subject: [PATCH 3/3] Add Multiline field type to InputBox --- SourceFiles/Messenger.cs | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/SourceFiles/Messenger.cs b/SourceFiles/Messenger.cs index b36f005..3cf42b6 100644 --- a/SourceFiles/Messenger.cs +++ b/SourceFiles/Messenger.cs @@ -598,6 +598,28 @@ public static DialogResult InputBox( }); }; } + if (field.ValueType == ValueTypes.Multiline) + { + field_Control = new TextBox + { + Text = field.Value, + Dock = DockStyle.Fill, + TextAlign = HorizontalAlignment.Left, + Multiline = true, + ScrollBars = ScrollBars.Vertical + }; + ((TextBox)field_Control).TextChanged += (sender, args) => + { + AddTextChangedDelay((TextBox)field_Control, ChangeDelayMS, text => + { + field.Value = ((TextBox)sender).Text; + + //aqui 'KeyValue' valida el nuevo valor y puede cancelarlo + ((TextBox)sender).Text = Convert.ToString(field.Value); + Err.SetError(field_Control, field.ErrorText); + }); + }; + } if (field.ValueType == ValueTypes.Password) { field_Control = new TextBox @@ -751,7 +773,22 @@ public static DialogResult InputBox( // Add controls to appropriate cells: Contenedor.Controls.Add(field_label, 0, currentRow); // Column 0 for labels - Contenedor.Controls.Add(field_Control, 1, currentRow); // Column 1 for text boxes + if (field.ValueType == ValueTypes.Multiline) + { + Contenedor.Controls.Add(field_Control, 1, currentRow); + const int spanRow = 6; + for (int i = 0; i < spanRow; i++) + { + currentRow++; + Contenedor.RowCount++; + Contenedor.RowStyles.Add(new RowStyle(SizeType.Absolute, field_Control.Height)); + } + Contenedor.SetRowSpan(field_Control, spanRow); + } + else + { + Contenedor.Controls.Add(field_Control, 1, currentRow); // Column 1 for text boxes + } Err.SetIconAlignment(field_Control, ErrorIconAlignment.MiddleLeft); @@ -982,7 +1019,8 @@ public enum ValueTypes Time, Boolean, Dynamic, - Password + Password, + Multiline } public string Key { get; set; }