From 89df6a1fb7e41e9501bc4d6df0cfbed5b9773dd2 Mon Sep 17 00:00:00 2001 From: Smurf-iv Date: Sat, 24 Jul 2021 13:34:16 +0100 Subject: [PATCH 1/2] - Make sure that the `NormalPanel` is the default style - Also Fixed the WrapLabel Style not being set correctly - Move some code to latest framework Code style Fixes #150 --- .../Controls Toolkit/KryptonLabel.cs | 71 +++++++------------ .../Controls Toolkit/KryptonWrapLabel.cs | 17 ++--- 2 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonLabel.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonLabel.cs index 0968d7e92..04fa27b41 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonLabel.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonLabel.cs @@ -13,6 +13,8 @@ #endregion +using System.ComponentModel; + namespace Krypton.Toolkit { /// @@ -54,11 +56,12 @@ public class KryptonLabel : VisualSimpleBase, IContentValues /// public KryptonLabel() { + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // The label cannot take the focus SetStyle(ControlStyles.Selectable, false); // Set default properties - _style = LabelStyle.NormalControl; + _style = LabelStyle.NormalPanel; _useMnemonic = true; _orientation = VisualOrientation.Top; _target = null; @@ -69,7 +72,7 @@ public KryptonLabel() Values.TextChanged += OnLabelTextChanged; // Create palette redirector - _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl); + _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalPanel); // Create the palette provider StateCommon = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); @@ -147,10 +150,7 @@ public override string Text } private bool ShouldSerializeText() - { - // Never serialize, let the label values serialize instead - return false; - } + => false; /// /// Resets the Text property to its default value. @@ -185,15 +185,23 @@ public virtual VisualOrientation Orientation } } + private bool ShouldSerializeOrientation() + => (_orientation != VisualOrientation.Top); + + private void ResetOrientation() + { + _orientation = VisualOrientation.Top; + } + /// /// Gets and sets the label style. /// [Category("Visuals")] [Description("Label style.")] + [DefaultValue(typeof(LabelStyle), "NormalPanel")] public LabelStyle LabelStyle { get => _style; - set { if (_style != value) @@ -205,15 +213,9 @@ public LabelStyle LabelStyle } } - private bool ShouldSerializeLabelStyle() - { - return (LabelStyle != LabelStyle.NormalControl); - } + private bool ShouldSerializeLabelStyle() => (LabelStyle != LabelStyle.NormalPanel); - private void ResetLabelStyle() - { - LabelStyle = LabelStyle.NormalControl; - } + private void ResetLabelStyle() => LabelStyle = LabelStyle.NormalPanel; /// /// Gets access to the label content. @@ -223,10 +225,7 @@ private void ResetLabelStyle() [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public LabelValues Values { get; } - private bool ShouldSerializeValues() - { - return !Values.IsDefault; - } + private bool ShouldSerializeValues() => !Values.IsDefault; /// /// Gets access to the common label appearance that other states can override. @@ -236,10 +235,7 @@ private bool ShouldSerializeValues() [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public PaletteContent StateCommon { get; } - private bool ShouldSerializeStateCommon() - { - return !StateCommon.IsDefault; - } + private bool ShouldSerializeStateCommon() => !StateCommon.IsDefault; /// /// Gets access to the disabled label appearance entries. @@ -249,10 +245,7 @@ private bool ShouldSerializeStateCommon() [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public PaletteContent StateDisabled { get; } - private bool ShouldSerializeStateDisabled() - { - return !StateDisabled.IsDefault; - } + private bool ShouldSerializeStateDisabled() => !StateDisabled.IsDefault; /// /// Gets access to the normal label appearance entries. @@ -262,10 +255,7 @@ private bool ShouldSerializeStateDisabled() [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public PaletteContent StateNormal { get; } - private bool ShouldSerializeStateNormal() - { - return !StateNormal.IsDefault; - } + private bool ShouldSerializeStateNormal() => !StateNormal.IsDefault; /// /// Gets or sets a value indicating whether an ampersand is included in the text of the control. @@ -367,10 +357,7 @@ public virtual void SetFixedState(PaletteState state) /// /// The state for which the image is needed. /// Image value. - public Image GetImage(PaletteState state) - { - return KryptonCommand?.ImageSmall ?? Values.GetImage(state); - } + public Image GetImage(PaletteState state) => KryptonCommand?.ImageSmall ?? Values.GetImage(state); /// /// Gets the image color that should be transparent. @@ -395,10 +382,7 @@ public Image GetImage(PaletteState state) /// Update the view elements based on the requested label style. /// /// New label style. - protected virtual void SetLabelStyle(LabelStyle style) - { - _paletteCommonRedirect.Style = CommonHelper.ContentStyleFromLabelStyle(style); - } + protected virtual void SetLabelStyle(LabelStyle style) => _paletteCommonRedirect.Style = CommonHelper.ContentStyleFromLabelStyle(style); /// /// Processes a mnemonic character. @@ -417,7 +401,7 @@ protected override bool ProcessMnemonic(char charCode) if (EnabledTarget) { // Do we have a target that can take the focus - if ((Target != null) && Target.CanFocus) + if (Target is { CanFocus: true }) { Target.Focus(); return true; @@ -440,7 +424,7 @@ protected override void OnClick(EventArgs e) if (EnabledTarget) { // Do we have a target that can take the focus - if ((Target != null) && Target.CanFocus) + if (Target is { CanFocus: true }) { Target.Focus(); } @@ -523,10 +507,7 @@ protected override bool EvalTransparentPaint() #endregion #region Implementation - private void OnLabelTextChanged(object sender, EventArgs e) - { - OnTextChanged(EventArgs.Empty); - } + private void OnLabelTextChanged(object sender, EventArgs e) => OnTextChanged(EventArgs.Empty); #endregion } } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonWrapLabel.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonWrapLabel.cs index 5aa76d94e..2501c099a 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonWrapLabel.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonWrapLabel.cs @@ -83,7 +83,7 @@ public KryptonWrapLabel() _redirector = CreateRedirector(); // Default properties - SetLabelStyle(LabelStyle.NormalControl); + SetLabelStyle(LabelStyle.NormalPanel); AutoSize = true; TabStop = false; } @@ -242,6 +242,7 @@ public override bool AutoSize /// [Category("Visuals")] [Description("Label style.")] + [DefaultValue(typeof(LabelStyle), "NormalPanel")] public LabelStyle LabelStyle { get => _labelStyle; @@ -257,9 +258,9 @@ public LabelStyle LabelStyle } } - private bool ShouldSerializeLabelStyle() => (LabelStyle != LabelStyle.NormalControl); + private bool ShouldSerializeLabelStyle() => (LabelStyle != LabelStyle.NormalPanel); - private void ResetLabelStyle() => LabelStyle = LabelStyle.NormalControl; + private void ResetLabelStyle() => LabelStyle = LabelStyle.NormalPanel; /// /// Gets or sets the palette to be applied. @@ -620,19 +621,13 @@ protected override void OnPaintBackground(PaintEventArgs pEvent) /// Create the redirector instance. /// /// PaletteRedirect derived class. - private PaletteRedirect CreateRedirector() - { - return new PaletteRedirect(_palette); - } + private PaletteRedirect CreateRedirector() => new PaletteRedirect(_palette); /// /// Update the view elements based on the requested label style. /// /// New label style. - private void SetLabelStyle(LabelStyle style) - { - _labelContentStyle = CommonHelper.ContentStyleFromLabelStyle(style); - } + private void SetLabelStyle(LabelStyle style) => _labelContentStyle = CommonHelper.ContentStyleFromLabelStyle(style); /// /// Update global event attachments. From 1477208324c13325e608c055ce11550db7e4d428 Mon Sep 17 00:00:00 2001 From: Smurf-iv Date: Sat, 24 Jul 2021 13:36:26 +0100 Subject: [PATCH 2/2] - Add the doc update --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fa5973499..19716c32a 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,9 @@ These packages only support .NET Framework >= 4.8, .NET Core 3.1 and .NET 6. ======= ## 2021-08-01 Build 2108 - August 2021 (Canary) +* Fixed [#150](https://github.com/Krypton-Suite/Standard-Toolkit/issues/150) + - Make sure that the `NormalPanel` is the default style + - Also Fixed the WrapLabel Style not being set correctly * Fixed [#202](https://github.com/Krypton-Suite/Standard-Toolkit/issues/202), `KryptonGroup` transparency * Remove the internal class Called `KryptonDataGridViewIconColumn` from design use [#27](https://github.com/Krypton-Suite/Standard-Toolkit/issues/27) - Put back the removed `CLSCompliant` and `ComVisible` assembly flags for backwards compatibility