diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index b3c52def..567a4738 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 98b472f6..4ca98abe 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FButton.Designer.cs b/SunnyUI.Demo/Controls/FButton.Designer.cs index d43180bd..ceb6e266 100644 --- a/SunnyUI.Demo/Controls/FButton.Designer.cs +++ b/SunnyUI.Demo/Controls/FButton.Designer.cs @@ -88,6 +88,8 @@ namespace Sunny.UI.Demo this.uiButton2 = new Sunny.UI.UIButton(); this.uiButton1 = new Sunny.UI.UIButton(); this.uiToolTip1 = new Sunny.UI.UIToolTip(this.components); + this.uiSwitch5 = new Sunny.UI.UISwitch(); + this.uiSwitch6 = new Sunny.UI.UISwitch(); ((System.ComponentModel.ISupportInitialize)(this.uiImageButton4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.uiImageButton3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.uiImageButton2)).BeginInit(); @@ -424,6 +426,7 @@ namespace Sunny.UI.Demo // uiSymbolButton18 // this.uiSymbolButton18.Cursor = System.Windows.Forms.Cursors.Hand; + this.uiSymbolButton18.Enabled = false; this.uiSymbolButton18.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiSymbolButton18.Location = new System.Drawing.Point(30, 395); this.uiSymbolButton18.MinimumSize = new System.Drawing.Size(1, 1); @@ -1098,11 +1101,39 @@ namespace Sunny.UI.Demo this.uiToolTip1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(239)))), ((int)(((byte)(239))))); this.uiToolTip1.OwnerDraw = true; // + // uiSwitch5 + // + this.uiSwitch5.ActiveText = "On"; + this.uiSwitch5.Enabled = false; + this.uiSwitch5.Font = new System.Drawing.Font("微软雅黑", 12F); + this.uiSwitch5.InActiveText = "Off"; + this.uiSwitch5.Location = new System.Drawing.Point(30, 520); + this.uiSwitch5.MinimumSize = new System.Drawing.Size(1, 1); + this.uiSwitch5.Name = "uiSwitch5"; + this.uiSwitch5.Size = new System.Drawing.Size(75, 29); + this.uiSwitch5.TabIndex = 116; + this.uiSwitch5.Text = "uiSwitch5"; + // + // uiSwitch6 + // + this.uiSwitch6.Active = true; + this.uiSwitch6.Enabled = false; + this.uiSwitch6.Font = new System.Drawing.Font("微软雅黑", 12F); + this.uiSwitch6.Location = new System.Drawing.Point(112, 520); + this.uiSwitch6.MinimumSize = new System.Drawing.Size(1, 1); + this.uiSwitch6.Name = "uiSwitch6"; + this.uiSwitch6.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; + this.uiSwitch6.Size = new System.Drawing.Size(75, 29); + this.uiSwitch6.TabIndex = 117; + this.uiSwitch6.Text = "uiSwitch6"; + // // FButton // this.AllowShowTitle = true; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.ClientSize = new System.Drawing.Size(800, 614); + this.Controls.Add(this.uiSwitch6); + this.Controls.Add(this.uiSwitch5); this.Controls.Add(this.uiSwitch3); this.Controls.Add(this.uiSwitch4); this.Controls.Add(this.uiSymbolButton26); @@ -1234,5 +1265,7 @@ namespace Sunny.UI.Demo private UIButton uiButton2; private UIButton uiButton1; private UIToolTip uiToolTip1; + private UISwitch uiSwitch5; + private UISwitch uiSwitch6; } } \ No newline at end of file diff --git a/SunnyUI/Controls/UISwitch.cs b/SunnyUI/Controls/UISwitch.cs index 660c6d72..6b19ec2b 100644 --- a/SunnyUI/Controls/UISwitch.cs +++ b/SunnyUI/Controls/UISwitch.cs @@ -19,6 +19,7 @@ * 2020-01-01: V2.2.0 增加文件说明 * 2020-04-25: V2.2.4 更新主题配置类 * 2021-05-06: V3.0.3 更新Active状态改变时触发ValueChanged事件 + * 2021-09-14: V3.0.7 增加Disabled颜色 ******************************************************************************/ using System; @@ -54,7 +55,7 @@ namespace Sunny.UI ShowText = false; ShowRect = false; foreColor = Color.White; - inActiveColor = Color.Silver; + inActiveColor = Color.Gray; fillColor = Color.White; } @@ -136,7 +137,7 @@ namespace Sunny.UI private Color inActiveColor; - [DefaultValue(typeof(Color), "Silver")] + [DefaultValue(typeof(Color), "Gray")] [Description("关闭颜色"), Category("SunnyUI")] public Color InActiveColor { @@ -195,15 +196,34 @@ namespace Sunny.UI rectColor = uiColor.SwitchActiveColor; fillColor = uiColor.SwitchFillColor; inActiveColor = uiColor.SwitchInActiveColor; + disabledColor = uiColor.RectDisableColor; + Invalidate(); + } + + private Color disabledColor; + [Description("不可用颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "173, 178, 181")] + public Color DisabledColor + { + get => rectDisableColor; + set => SetRectDisableColor(value); + } + + protected override void OnEnabledChanged(EventArgs e) + { + base.OnEnabledChanged(e); Invalidate(); } protected override void OnPaintFill(Graphics g, GraphicsPath path) { + Color color = Active ? ActiveColor : InActiveColor; + if (!Enabled) color = disabledColor; + if (SwitchShape == UISwitchShape.Round) { Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); - g.FillRoundRectangle(Active ? ActiveColor : InActiveColor, rect, rect.Height); + g.FillRoundRectangle(color, rect, rect.Height); int width = Width - 3 - 1 - 3 - (rect.Height - 6); if (!Active) @@ -223,7 +243,7 @@ namespace Sunny.UI if (SwitchShape == UISwitchShape.Square) { Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); - g.FillRoundRectangle(Active ? ActiveColor : InActiveColor, rect, Radius); + g.FillRoundRectangle(color, rect, Radius); int width = Width - 3 - 1 - 3 - (rect.Height - 6); if (!Active) diff --git a/SunnyUI/Style/UIStyleColor.cs b/SunnyUI/Style/UIStyleColor.cs index 01d43a9e..d4cd4c4e 100644 --- a/SunnyUI/Style/UIStyleColor.cs +++ b/SunnyUI/Style/UIStyleColor.cs @@ -93,7 +93,7 @@ namespace Sunny.UI public virtual Color SwitchActiveColor => PrimaryColor; - public virtual Color SwitchInActiveColor => Color.Silver; + public virtual Color SwitchInActiveColor => Color.Gray; public virtual Color SwitchFillColor => Color.White;