From c04959f0de2cdc7b3cb5f14a113628115079c126 Mon Sep 17 00:00:00 2001 From: Smurf-iv Date: Sun, 12 Sep 2021 17:24:16 +0100 Subject: [PATCH] - Restore layout to orginal Krypton Intent Fixes: #316 --- Documents/Help/Changelog.md | 4 +- .../Controls Toolkit/KryptonInputBox.cs | 328 +++++++----------- 2 files changed, 131 insertions(+), 201 deletions(-) diff --git a/Documents/Help/Changelog.md b/Documents/Help/Changelog.md index 2df1802e6..467d9df04 100644 --- a/Documents/Help/Changelog.md +++ b/Documents/Help/Changelog.md @@ -4,8 +4,10 @@ * New `KryptonColorButton` action list options * The `KryptonColorButton` now uses the `KryptonColorDialog` * Fixed [#315](https://github.com/Krypton-Suite/Standard-Toolkit/issues/315), When adding a new KContextmenu, How do you change it's name etc - - Sort out the Callback actions that were removed +- Sort out the Callback actions that were removed * Fixed [#323](https://github.com/Krypton-Suite/Standard-Toolkit/issues/323), `KryptonCheckButton` Click removes image +- Sort out the Callback actions that were removed +* Fixed [#316](https://github.com/Krypton-Suite/Standard-Toolkit/issues/316), Restore `KryptonKInputBox` layout to initial intent. ======= diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonInputBox.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonInputBox.cs index 4cd8a1508..dbf77ff4d 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonInputBox.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonInputBox.cs @@ -11,7 +11,6 @@ #endregion -#nullable enable namespace Krypton.Toolkit { /// @@ -35,32 +34,30 @@ public class KryptonInputBox : KryptonForm private readonly string _defaultResponse; private readonly string _cueText; private readonly Font _cueTypeface; - private KryptonPanel _panelMessage; - private KryptonWrapLabel _labelPrompt; - private KryptonTextBox _textBoxResponse; - private KryptonButton _buttonOk; - private KryptonButton _buttonCancel; #endregion + private KryptonInputBox() + { + InitializeComponent(); + } + #region Identity -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private KryptonInputBox(string prompt, -#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. string caption, - string defaultResposne, + string defaultResponse, string cueText, - Color? cueColour, - Font? cueTypeface, - bool? usePasswordOption) + Color cueColour, + Font cueTypeface, + bool usePasswordOption) { // Store incoming values _prompt = prompt; _caption = caption; - _defaultResponse = defaultResposne; + _defaultResponse = defaultResponse; _cueText = cueText; - _cueColour = cueColour ?? Color.Gray; - _cueTypeface = cueTypeface ?? new Font("Segoe UI", 9f); - _usePasswordOption = usePasswordOption ?? false; + _cueColour = cueColour; + _cueTypeface = cueTypeface; + _usePasswordOption = usePasswordOption; // Create the form contents InitializeComponent(); @@ -71,9 +68,6 @@ private KryptonInputBox(string prompt, UpdateCue(); UpdateButtons(); - - // Finally calculate and set form sizing - UpdateSizing(); } /// @@ -91,56 +85,6 @@ protected override void Dispose(bool disposing) #endregion #region Public - /// - /// Displays an input box with the provided prompt. - /// - /// The text to display as an input prompt. - /// Input string. - public static string Show(string prompt) => InternalShow(null, prompt, string.Empty, string.Empty, string.Empty, null, null, null); - - /// - /// Displays an input box in front of the specified object and with the provided prompt. - /// - /// Owner of the modal dialog box. - /// The text to display as an input prompt. - /// Input string. - public static string Show(IWin32Window owner, string prompt) => InternalShow(owner, prompt, string.Empty, string.Empty, string.Empty, null, null, null); - - /// - /// Displays an input box with provided prompt and caption. - /// - /// The text to display as an input prompt. - /// The text to display in the title bar of the input box. - /// Input string. - public static string Show(string prompt, string caption) => InternalShow(null, prompt, caption, string.Empty, string.Empty, null, null, null); - - /// - /// Displays an input box in front of the specified object and with the provided prompt and caption. - /// - /// Owner of the modal dialog box. - /// The text to display as an input prompt. - /// The text to display in the title bar of the input box. - /// Input string. - public static string Show(IWin32Window owner, string prompt, string caption) => InternalShow(owner, prompt, caption, string.Empty, string.Empty, null, null, null); - - /// - /// Displays an input box with provided prompt and caption and defaulted response string. - /// - /// The text to display as an input prompt. - /// The text to display in the title bar of the input box. - /// Default response text.. - /// Input string. - public static string Show(string prompt, string caption, string defaultResponse) => InternalShow(null, prompt, caption, defaultResponse, string.Empty, null, null, null); - - /// - /// Displays an input box in front of the specified object and with the provided prompt and caption and defaulted response string. - /// - /// Owner of the modal dialog box. - /// The text to display as an input prompt. - /// The text to display in the title bar of the input box. - /// Default response text.. - /// Input string. - public static string Show(IWin32Window owner, string prompt, string caption, string defaultResponse) => InternalShow(owner, prompt, caption, defaultResponse, string.Empty, null, null, null); /// /// Displays an input box with provided prompt and caption and defaulted response string. @@ -153,7 +97,14 @@ protected override void Dispose(bool disposing) /// The cue font. /// Enables the password option. /// Input string. - public static string Show(string prompt, string caption, string defaultResponse, string cueText, Color cueColour, Font cueTypeface, bool usePasswordOption) => InternalShow(null, prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption); + public static string Show(string prompt, + string caption = @"", + string defaultResponse = @"", + string cueText = @"", + Color cueColour = new Color(), + Font cueTypeface = null, + bool usePasswordOption = false) + => InternalShow(null, prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption); /// /// DDisplays an input box in front of the specified object and with the provided prompt and caption and defaulted response string. @@ -167,29 +118,33 @@ protected override void Dispose(bool disposing) /// The cue font. /// Enables the password option. /// Input string. - public static string Show(IWin32Window owner, string prompt, string caption, string defaultResponse, string cueText, Color cueColour, Font cueTypeface, bool usePasswordOption) => InternalShow(owner, prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption); + public static string Show(IWin32Window owner, string prompt, + string caption = @"", + string defaultResponse = @"", + string cueText = @"", + Color cueColour = new Color(), + Font cueTypeface = null, + bool usePasswordOption = false) + => InternalShow(owner, prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption); #endregion #region Implementation - private static string InternalShow(IWin32Window? owner, + private static string InternalShow(IWin32Window owner, string prompt, string caption, string defaultResponse, string cueText, - Color? cueColour, - Font? cueTypeface, - bool? usePasswordOption) + Color cueColour, + Font cueTypeface, + bool usePasswordOption) { // If do not have an owner passed in then get the active window and use that instead IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow()); // Show input box window as a modal dialog and then dispose of it afterwards using KryptonInputBox ib = new(prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption); - if (showOwner == null) - ib.StartPosition = FormStartPosition.CenterScreen; - else - ib.StartPosition = FormStartPosition.CenterParent; + ib.StartPosition = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent; return ib.ShowDialog(showOwner) == DialogResult.OK ? ib.InputResponse : string.Empty; } @@ -208,9 +163,11 @@ private void UpdateCue() { _textBoxResponse.CueHint.CueHintText = _cueText; - _textBoxResponse.CueHint.Color1 = _cueColour; + if ( !_cueColour.IsEmpty ) + _textBoxResponse.CueHint.Color1 = _cueColour; - _textBoxResponse.CueHint.Font = _cueTypeface; + if ( _cueTypeface != null ) + _textBoxResponse.CueHint.Font = _cueTypeface; } private void UpdateButtons() @@ -219,56 +176,7 @@ private void UpdateButtons() _buttonCancel.Text = KryptonManager.Strings.Cancel; } - private void UpdateSizing() - { - UpdateButtonSizing(); - UpdatePromptSizing(); - UpdateResponseSizing(); - ClientSize = new Size(_buttonCancel.Right + GAP, _textBoxResponse.Bottom + GAP); - } - - private void UpdatePromptSizing() - { - // Update size of the message label but with a maximum width - using Graphics g = CreateGraphics(); - // Find size of the label when it has a maximum length of 250, this tells us the height - // required to fully show the label with the prompt. - _labelPrompt.UpdateFont(); - Size messageSize = g.MeasureString(_prompt, _labelPrompt.Font, 250).ToSize(); - - // Work out DPI adjustment factor - float factorX = g.DpiX > 96 ? (1.0f * g.DpiX / 96) : 1.0f; - float factorY = g.DpiY > 96 ? (1.0f * g.DpiY / 96) : 1.0f; - messageSize.Width = (int)(messageSize.Width * factorX); - messageSize.Height = (int)(messageSize.Height * factorY); - - _labelPrompt.Location = new Point(GAP, GAP); - _labelPrompt.Size = new Size(255, Math.Max(messageSize.Height, _buttonCancel.Bottom - _buttonOk.Top)); - - } - - private void UpdateButtonSizing() - { - Size buttonOKSize = _buttonOk.GetPreferredSize(Size.Empty); - Size buttonCancelSize = _buttonCancel.GetPreferredSize(Size.Empty); - - // Make both buttons the size of the largest one - Size largestButton = new(Math.Max(buttonOKSize.Width, buttonCancelSize.Width), Math.Max(buttonOKSize.Height, buttonCancelSize.Height)); - _buttonOk.Size = largestButton; - _buttonCancel.Size = largestButton; - // Position the buttons relative to the top left of the owning panel - _buttonOk.Location = new Point(_panelMessage.Right - _buttonOk.Width - GAP, GAP); - _buttonCancel.Location = new Point(_panelMessage.Right - _buttonCancel.Width - GAP, _buttonOk.Bottom + GAP / 2); - - } - - private void UpdateResponseSizing() - { - // Position the response text box below the prompt - _textBoxResponse.Location = new Point(GAP, _labelPrompt.Bottom + GAP); - _textBoxResponse.Width = _buttonOk.Right - _textBoxResponse.Left; - } private void button_keyDown(object sender, KeyEventArgs e) { @@ -279,94 +187,114 @@ private void button_keyDown(object sender, KeyEventArgs e) private void InitializeComponent() { - _panelMessage = new KryptonPanel(); - _textBoxResponse = new KryptonTextBox(); - _labelPrompt = new KryptonWrapLabel(); - _buttonCancel = new KryptonButton(); - _buttonOk = new KryptonButton(); - ((ISupportInitialize)(_panelMessage)).BeginInit(); - _panelMessage.SuspendLayout(); - SuspendLayout(); + this._panelMessage = new Krypton.Toolkit.KryptonPanel(); + this._textBoxResponse = new Krypton.Toolkit.KryptonTextBox(); + this._labelPrompt = new Krypton.Toolkit.KryptonWrapLabel(); + this._buttonCancel = new Krypton.Toolkit.KryptonButton(); + this._buttonOk = new Krypton.Toolkit.KryptonButton(); + this.kryptonBorderEdge1 = new Krypton.Toolkit.KryptonBorderEdge(); + ((System.ComponentModel.ISupportInitialize)(this._panelMessage)).BeginInit(); + this._panelMessage.SuspendLayout(); + this.SuspendLayout(); // // _panelMessage // - _panelMessage.Controls.Add(_textBoxResponse); - _panelMessage.Controls.Add(_labelPrompt); - _panelMessage.Controls.Add(_buttonCancel); - _panelMessage.Controls.Add(_buttonOk); - _panelMessage.Dock = DockStyle.Fill; - _panelMessage.Location = new Point(0, 0); - _panelMessage.Name = "_panelMessage"; - _panelMessage.Size = new Size(357, 118); - _panelMessage.TabIndex = 0; + this._panelMessage.Controls.Add(this.kryptonBorderEdge1); + this._panelMessage.Controls.Add(this._textBoxResponse); + this._panelMessage.Controls.Add(this._labelPrompt); + this._panelMessage.Controls.Add(this._buttonCancel); + this._panelMessage.Controls.Add(this._buttonOk); + this._panelMessage.Dock = System.Windows.Forms.DockStyle.Fill; + this._panelMessage.Location = new System.Drawing.Point(0, 0); + this._panelMessage.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this._panelMessage.Name = "_panelMessage"; + this._panelMessage.Size = new System.Drawing.Size(476, 145); + this._panelMessage.TabIndex = 0; // // _textBoxResponse // - _textBoxResponse.Location = new Point(12, 86); - _textBoxResponse.Name = "_textBoxResponse"; - _textBoxResponse.Size = new Size(333, 20); - _textBoxResponse.TabIndex = 0; + this._textBoxResponse.Location = new System.Drawing.Point(16, 42); + this._textBoxResponse.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this._textBoxResponse.Name = "_textBoxResponse"; + this._textBoxResponse.Size = new System.Drawing.Size(444, 27); + this._textBoxResponse.TabIndex = 0; + this._textBoxResponse.KeyDown += new System.Windows.Forms.KeyEventHandler(this.button_keyDown); // // _labelPrompt // - _labelPrompt.AutoSize = false; - _labelPrompt.Font = new Font("Segoe UI", 9F); - _labelPrompt.ForeColor = Color.FromArgb(30, 57, 91); - _labelPrompt.LabelStyle = LabelStyle.NormalPanel; - _labelPrompt.Location = new Point(12, 12); - _labelPrompt.Margin = new Padding(0); - _labelPrompt.Name = "_labelPrompt"; - _labelPrompt.Size = new Size(78, 15); - _labelPrompt.Text = @"Prompt"; + this._labelPrompt.Location = new System.Drawing.Point(14, 15); + this._labelPrompt.Margin = new System.Windows.Forms.Padding(0); + this._labelPrompt.Name = "_labelPrompt"; + this._labelPrompt.Size = new System.Drawing.Size(58, 20); + this._labelPrompt.Text = "Prompt"; // // _buttonCancel // - _buttonCancel.Anchor = AnchorStyles.Top | AnchorStyles.Right; - _buttonCancel.AutoSize = true; - _buttonCancel.DialogResult = DialogResult.Cancel; - _buttonCancel.Location = new Point(295, 43); - _buttonCancel.Margin = new Padding(0); - _buttonCancel.MinimumSize = new Size(50, 26); - _buttonCancel.Name = "_buttonCancel"; - _buttonCancel.Size = new Size(50, 26); - _buttonCancel.TabIndex = 2; - _buttonCancel.Values.Text = KryptonManager.GlobalStrings.Cancel; - _buttonCancel.KeyDown += button_keyDown; + this._buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this._buttonCancel.AutoSize = true; + this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this._buttonCancel.Location = new System.Drawing.Point(384, 104); + this._buttonCancel.Margin = new System.Windows.Forms.Padding(0); + this._buttonCancel.MinimumSize = new System.Drawing.Size(67, 32); + this._buttonCancel.Name = "_buttonCancel"; + this._buttonCancel.Size = new System.Drawing.Size(73, 32); + this._buttonCancel.TabIndex = 2; + this._buttonCancel.Values.Text = "Cance&l"; + this._buttonCancel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.button_keyDown); + // + // _buttonOk // - // _buttonOK + this._buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this._buttonOk.AutoSize = true; + this._buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; + this._buttonOk.Location = new System.Drawing.Point(284, 104); + this._buttonOk.Margin = new System.Windows.Forms.Padding(0); + this._buttonOk.MinimumSize = new System.Drawing.Size(67, 32); + this._buttonOk.Name = "_buttonOk"; + this._buttonOk.Size = new System.Drawing.Size(67, 32); + this._buttonOk.TabIndex = 1; + this._buttonOk.Values.Text = "&OK"; + this._buttonOk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.button_keyDown); // - _buttonOk.Anchor = AnchorStyles.Top | AnchorStyles.Right; - _buttonOk.AutoSize = true; - _buttonOk.DialogResult = DialogResult.OK; - _buttonOk.Location = new Point(295, 12); - _buttonOk.Margin = new Padding(0); - _buttonOk.MinimumSize = new Size(50, 26); - _buttonOk.Name = "_buttonOk"; - _buttonOk.Size = new Size(50, 26); - _buttonOk.TabIndex = 1; - _buttonOk.Values.Text = KryptonManager.GlobalStrings.OK; - _buttonOk.KeyDown += button_keyDown; + // kryptonBorderEdge1 // - // KryptonInputBox + this.kryptonBorderEdge1.AutoSize = false; + this.kryptonBorderEdge1.Location = new System.Drawing.Point(0, 84); + this.kryptonBorderEdge1.Margin = new System.Windows.Forms.Padding(0); + this.kryptonBorderEdge1.Name = "kryptonBorderEdge1"; + this.kryptonBorderEdge1.Size = new System.Drawing.Size(476, 2); + this.kryptonBorderEdge1.Text = "kryptonBorderEdge1"; // - AutoScaleDimensions = new SizeF(6F, 13F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(357, 118); - Controls.Add(_panelMessage); - FormBorderStyle = FormBorderStyle.FixedDialog; - MaximizeBox = false; - MinimizeBox = false; - Name = "KryptonInputBox"; - ShowIcon = false; - ShowInTaskbar = false; - SizeGripStyle = SizeGripStyle.Hide; - StartPosition = FormStartPosition.CenterParent; - ((ISupportInitialize)(_panelMessage)).EndInit(); - _panelMessage.ResumeLayout(false); - _panelMessage.PerformLayout(); - ResumeLayout(false); + // KryptonInputBox1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(476, 145); + this.Controls.Add(this._panelMessage); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "KryptonInputBox1"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + ((System.ComponentModel.ISupportInitialize)(this._panelMessage)).EndInit(); + this._panelMessage.ResumeLayout(false); + this._panelMessage.PerformLayout(); + this.ResumeLayout(false); } + #endregion + + private KryptonPanel _panelMessage; + private KryptonWrapLabel _labelPrompt; + private KryptonTextBox _textBoxResponse; + private KryptonButton _buttonOk; + private KryptonButton _buttonCancel; + private KryptonBorderEdge kryptonBorderEdge1; + } } \ No newline at end of file