From 90e9439b6edfd93d3397bc1b73719ebf82ed3fd8 Mon Sep 17 00:00:00 2001 From: ThoNohT Date: Fri, 15 Jul 2016 12:57:53 +0200 Subject: [PATCH] Don't raise stylechanged events when setting style The style changed events are only supposed to be raised when a style is changed via the user interface. When this happens programmatically, this can result in incorrect states. --- NohBoard/Controls/FontChooser.cs | 1 - NohBoard/Controls/KeySubStylePanel.cs | 19 ++++++++++++++----- NohBoard/Controls/MouseSpeedStylePanel.cs | 13 +++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/NohBoard/Controls/FontChooser.cs b/NohBoard/Controls/FontChooser.cs index 44faf53..996e589 100644 --- a/NohBoard/Controls/FontChooser.cs +++ b/NohBoard/Controls/FontChooser.cs @@ -79,7 +79,6 @@ public FontChooser() get { return this.font; } set { - Console.WriteLine($"Font changed to {value.Name}"); this.font = value; this.DisplayLabel.Font = value; this.Refresh(); diff --git a/NohBoard/Controls/KeySubStylePanel.cs b/NohBoard/Controls/KeySubStylePanel.cs index a9b7ef1..d38f69b 100644 --- a/NohBoard/Controls/KeySubStylePanel.cs +++ b/NohBoard/Controls/KeySubStylePanel.cs @@ -27,6 +27,11 @@ namespace ThoNohT.NohBoard.Controls /// public partial class KeySubStylePanel : UserControl { + /// + /// Indicates whether the style is being programatically set, this should not raise events. + /// + private bool setting; + #region Events /// @@ -79,6 +84,8 @@ public KeySubStyle SubStyle } set { + this.setting = true; + this.clrBackground.Color = value.Background; this.txtBackgoundImage.Text = value.BackgroundImageFileName.SanitizeFilename(); @@ -88,6 +95,8 @@ public KeySubStyle SubStyle this.clrOutline.Color = value.Outline; this.chkShowOutline.Checked = value.ShowOutline; this.udOutlineWidth.Value = value.OutlineWidth; + + this.setting = false; } } @@ -109,7 +118,7 @@ public string Title /// private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color) { - this.StyleChanged?.Invoke(this.SubStyle); + if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle); } /// @@ -117,7 +126,7 @@ private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color) /// private void fntText_FontChanged(FontChooser sender, System.Drawing.Font font) { - this.StyleChanged?.Invoke(this.SubStyle); + if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle); } /// @@ -125,7 +134,7 @@ private void fntText_FontChanged(FontChooser sender, System.Drawing.Font font) /// private void chkShowOutline_CheckedChanged(object sender, System.EventArgs e) { - this.StyleChanged?.Invoke(this.SubStyle); + if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle); } /// @@ -133,7 +142,7 @@ private void chkShowOutline_CheckedChanged(object sender, System.EventArgs e) /// private void udOutlineWidth_ValueChanged(object sender, System.EventArgs e) { - this.StyleChanged?.Invoke(this.SubStyle); + if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle); } /// @@ -141,7 +150,7 @@ private void udOutlineWidth_ValueChanged(object sender, System.EventArgs e) /// private void txtBackgoundImage_TextChanged(object sender, System.EventArgs e) { - this.StyleChanged?.Invoke(this.SubStyle); + if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle); } #endregion Control event handlers diff --git a/NohBoard/Controls/MouseSpeedStylePanel.cs b/NohBoard/Controls/MouseSpeedStylePanel.cs index 9ee005a..3274d1b 100644 --- a/NohBoard/Controls/MouseSpeedStylePanel.cs +++ b/NohBoard/Controls/MouseSpeedStylePanel.cs @@ -27,6 +27,11 @@ namespace ThoNohT.NohBoard.Controls /// public partial class MouseSpeedStylePanel : UserControl { + /// + /// Indicates whether the style is currently being programmatically set, this should not raise events. + /// + private bool setting; + #region Events /// @@ -73,9 +78,13 @@ public MouseSpeedIndicatorStyle IndicatorStyle } set { + this.setting = true; + this.clrInner.Color = value.InnerColor; this.clrOuter.Color = value.OuterColor; this.udOutlineWidth.Value = value.OutlineWidth; + + this.setting = false; } } @@ -97,7 +106,7 @@ public string Title /// private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color) { - this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle); + if (!this.setting) this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle); } /// @@ -105,7 +114,7 @@ private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color) /// private void udOutlineWidth_ValueChanged(object sender, System.EventArgs e) { - this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle); + if (!this.setting) this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle); } #endregion Methods