From 70c3a7d6900bc378d234b61ede63fdb1af0f049d Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 16 Nov 2023 22:53:00 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E9=87=8D=E6=9E=84=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIDataGridView.cs | 2 - SunnyUI/Controls/UIFlowLayoutPanel.cs | 32 ++++++++---- SunnyUI/Controls/UIImageListBox.cs | 73 +++++++++++++++++++++++---- SunnyUI/Controls/UIListBox.cs | 32 +++++++++--- SunnyUI/Controls/UIRichTextBox.cs | 40 +++++++++++---- SunnyUI/Controls/UITextBox.cs | 32 +++++++++--- 6 files changed, 166 insertions(+), 45 deletions(-) diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index 2214d52b..4d0f2d1d 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -1019,8 +1019,6 @@ namespace Sunny.UI scrollBarColor = UIStyles.Blue.GridBarForeColor; scrollBarBackColor = UIStyles.Blue.GridBarFillColor; scrollBarRectColor = VBar.RectColor = UIStyles.Blue.RectColor; - scrollBarColor = UIStyles.Blue.GridBarForeColor; - scrollBarBackColor = UIStyles.Blue.GridBarFillColor; } } diff --git a/SunnyUI/Controls/UIFlowLayoutPanel.cs b/SunnyUI/Controls/UIFlowLayoutPanel.cs index 2b4195c2..516f27c9 100644 --- a/SunnyUI/Controls/UIFlowLayoutPanel.cs +++ b/SunnyUI/Controls/UIFlowLayoutPanel.cs @@ -58,9 +58,8 @@ namespace Sunny.UI Panel.ControlRemoved += Panel_ControlRemoved; Panel.Scroll += Panel_Scroll; Panel.MouseWheel += Panel_MouseWheel; - Panel.MouseEnter += Panel_MouseEnter; - Panel.MouseClick += Panel_MouseClick; Panel.ClientSizeChanged += Panel_ClientSizeChanged; + Panel.BackColor = UIStyles.Blue.PlainColor; VBar.ValueChanged += VBar_ValueChanged; HBar.ValueChanged += HBar_ValueChanged; @@ -328,7 +327,7 @@ namespace Sunny.UI base.SetStyleColor(uiColor); Panel.BackColor = uiColor.PlainColor; - if (HBar != null) + if (HBar != null && HBar.Style == UIStyle.Inherited) { HBar.ForeColor = uiColor.GridBarForeColor; HBar.HoverColor = uiColor.ButtonFillHoverColor; @@ -338,7 +337,7 @@ namespace Sunny.UI scrollBarBackColor = uiColor.GridBarFillColor; } - if (VBar != null) + if (VBar != null && VBar.Style == UIStyle.Inherited) { VBar.ForeColor = uiColor.GridBarForeColor; VBar.HoverColor = uiColor.ButtonFillHoverColor; @@ -370,6 +369,7 @@ namespace Sunny.UI scrollBarColor = value; HBar.HoverColor = HBar.PressColor = HBar.ForeColor = value; VBar.HoverColor = VBar.PressColor = VBar.ForeColor = value; + HBar.Style = VBar.Style = UIStyle.Custom; Invalidate(); } } @@ -389,18 +389,30 @@ namespace Sunny.UI scrollBarBackColor = value; HBar.FillColor = value; VBar.FillColor = value; + HBar.Style = VBar.Style = UIStyle.Custom; Invalidate(); } } - private void Panel_MouseClick(object sender, MouseEventArgs e) + /// + /// 滚动条主题样式 + /// + [DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")] + public bool ScrollBarStyleInherited { - //Panel.Focus(); - } + get => HBar != null && HBar.Style == UIStyle.Inherited; + set + { + if (value) + { + if (HBar != null) HBar.Style = UIStyle.Inherited; + if (VBar != null) VBar.Style = UIStyle.Inherited; - private void Panel_MouseEnter(object sender, EventArgs e) - { - //Panel.Focus(); + scrollBarColor = UIStyles.Blue.GridBarForeColor; + scrollBarBackColor = UIStyles.Blue.GridBarFillColor; + } + + } } protected override void OnGotFocus(EventArgs e) diff --git a/SunnyUI/Controls/UIImageListBox.cs b/SunnyUI/Controls/UIImageListBox.cs index 33731ffe..b4d50356 100644 --- a/SunnyUI/Controls/UIImageListBox.cs +++ b/SunnyUI/Controls/UIImageListBox.cs @@ -53,7 +53,6 @@ namespace Sunny.UI bar.Width = SystemInformation.VerticalScrollBarWidth + 2; bar.Parent = this; bar.Dock = DockStyle.None; - bar.Style = UIStyle.Custom; bar.Visible = false; listbox.Parent = this; @@ -93,6 +92,63 @@ namespace Sunny.UI listbox?.Dispose(); } + private Color scrollBarColor = Color.FromArgb(80, 160, 255); + + /// + /// 填充颜色,当值为背景色或透明色或空值则不填充 + /// + [Description("滚动条填充颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "80, 160, 255")] + public Color ScrollBarColor + { + get => scrollBarColor; + set + { + scrollBarColor = value; + bar.HoverColor = bar.PressColor = bar.ForeColor = value; + bar.Style = UIStyle.Custom; + Invalidate(); + } + } + + private Color scrollBarBackColor = Color.FromArgb(243, 249, 255); + + /// + /// 填充颜色,当值为背景色或透明色或空值则不填充 + /// + [Description("滚动条背景颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "243, 249, 255")] + public Color ScrollBarBackColor + { + get => scrollBarBackColor; + set + { + scrollBarBackColor = value; + bar.FillColor = value; + bar.Style = UIStyle.Custom; + Invalidate(); + } + } + + /// + /// 滚动条主题样式 + /// + [DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")] + public bool ScrollBarStyleInherited + { + get => bar != null && bar.Style == UIStyle.Inherited; + set + { + if (value) + { + if (bar != null) bar.Style = UIStyle.Inherited; + + scrollBarColor = UIStyles.Blue.ListBarForeColor; + scrollBarBackColor = UIStyles.Blue.ListBarFillColor; + } + } + } + private int scrollBarWidth = 0; [DefaultValue(0), Category("SunnyUI"), Description("垂直滚动条宽度,最小为原生滚动条宽度")] @@ -246,9 +302,9 @@ namespace Sunny.UI { bar.Top = 2; bar.Height = Height - 4; - int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth(), ScrollBarWidth); + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + Padding.Right, ScrollBarWidth); bar.Width = barWidth + 1; - bar.Left = Width - barWidth - 2; + bar.Left = Width - barWidth - 3; } private void Listbox_BeforeDrawItem(object sender, ListBox.ObjectCollection items, DrawItemEventArgs e) @@ -326,12 +382,15 @@ namespace Sunny.UI public override void SetStyleColor(UIBaseStyle uiColor) { base.SetStyleColor(uiColor); - if (bar != null) + if (bar != null && bar.Style == UIStyle.Inherited) { bar.ForeColor = uiColor.ListBarForeColor; bar.HoverColor = uiColor.ButtonFillHoverColor; bar.PressColor = uiColor.ButtonFillPressColor; bar.FillColor = uiColor.ListBarFillColor; + + scrollBarColor = uiColor.ListBarForeColor; + scrollBarBackColor = uiColor.ListBarFillColor; } hoverColor = uiColor.ListItemHoverColor; @@ -820,11 +879,7 @@ namespace Sunny.UI public Color HoverColor { get => hoverColor; - set - { - hoverColor = value; - Invalidate(); - } + set => hoverColor = value; } private int lastIndex = -1; diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index 7e48dcaf..143e8209 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -31,6 +31,7 @@ * 2022-05-15: V3.1.8 增加滚动条颜色设置 * 2022-09-05: V3.2.3 修复Click,DoubleClick事件 * 2022-11-03: V3.2.6 增加了可设置垂直滚动条宽度的属性 + * 2023-11-16: V3.5.2 重构主题 ******************************************************************************/ using System; @@ -60,7 +61,6 @@ namespace Sunny.UI bar.Width = SystemInformation.VerticalScrollBarWidth + 2; bar.Parent = this; bar.Dock = DockStyle.None; - bar.Style = UIStyle.Custom; bar.Visible = false; listbox.Parent = this; @@ -150,7 +150,7 @@ namespace Sunny.UI { scrollBarColor = value; bar.HoverColor = bar.PressColor = bar.ForeColor = value; - _style = UIStyle.Custom; + bar.Style = UIStyle.Custom; Invalidate(); } } @@ -169,11 +169,30 @@ namespace Sunny.UI { scrollBarBackColor = value; bar.FillColor = value; - _style = UIStyle.Custom; + bar.Style = UIStyle.Custom; Invalidate(); } } + /// + /// 滚动条主题样式 + /// + [DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")] + public bool ScrollBarStyleInherited + { + get => bar != null && bar.Style == UIStyle.Inherited; + set + { + if (value) + { + if (bar != null) bar.Style = UIStyle.Inherited; + + scrollBarColor = UIStyles.Blue.ListBarForeColor; + scrollBarBackColor = UIStyles.Blue.ListBarFillColor; + } + } + } + private void Listbox_DrawItem(object sender, DrawItemEventArgs e) { DrawItem?.Invoke(sender, e); @@ -436,9 +455,9 @@ namespace Sunny.UI { bar.Top = 2; bar.Height = Height - 4; - int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth(), ScrollBarWidth); + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + Padding.Right, ScrollBarWidth); bar.Width = barWidth + 1; - bar.Left = Width - barWidth - 2; + bar.Left = Width - barWidth - 3; } private void Listbox_BeforeDrawItem(object sender, ObjectCollection items, DrawItemEventArgs e) @@ -498,7 +517,7 @@ namespace Sunny.UI { base.SetStyleColor(uiColor); - if (bar != null) + if (bar != null && bar.Style == UIStyle.Inherited) { bar.ForeColor = uiColor.ListBarForeColor; bar.HoverColor = uiColor.ButtonFillHoverColor; @@ -627,7 +646,6 @@ namespace Sunny.UI { hoverColor = value; listbox.HoverColor = hoverColor; - _style = UIStyle.Custom; } } diff --git a/SunnyUI/Controls/UIRichTextBox.cs b/SunnyUI/Controls/UIRichTextBox.cs index 6231713a..9a0fbda4 100644 --- a/SunnyUI/Controls/UIRichTextBox.cs +++ b/SunnyUI/Controls/UIRichTextBox.cs @@ -56,7 +56,6 @@ namespace Sunny.UI edit.Click += Edit_Click; bar.Parent = this; - bar.Style = UIStyle.Custom; bar.Visible = false; bar.ValueChanged += Bar_ValueChanged; bar.MouseEnter += Bar_MouseEnter; @@ -320,7 +319,7 @@ namespace Sunny.UI edit.BackColor = GetFillColor(); edit.ForeColor = GetForeColor(); - if (bar != null) + if (bar != null && bar.Style == UIStyle.Inherited) { bar.ForeColor = uiColor.PrimaryColor; bar.HoverColor = uiColor.ButtonFillHoverColor; @@ -331,6 +330,25 @@ namespace Sunny.UI } } + /// + /// 滚动条主题样式 + /// + [DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")] + public bool ScrollBarStyleInherited + { + get => bar != null && bar.Style == UIStyle.Inherited; + set + { + if (value) + { + if (bar != null) bar.Style = UIStyle.Inherited; + scrollBarColor = UIStyles.Blue.PrimaryColor; + scrollBarBackColor = UIStyles.Blue.EditorBackColor; + } + + } + } + private Color scrollBarColor = Color.FromArgb(80, 160, 255); /// @@ -345,6 +363,7 @@ namespace Sunny.UI { scrollBarColor = value; bar.HoverColor = bar.PressColor = bar.ForeColor = value; + bar.Style = UIStyle.Custom; Invalidate(); } } @@ -363,6 +382,7 @@ namespace Sunny.UI { scrollBarBackColor = value; bar.FillColor = value; + bar.Style = UIStyle.Custom; Invalidate(); } } @@ -451,13 +471,10 @@ namespace Sunny.UI public void SetScrollInfo() { - int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 1, ScrollBarWidth); - bar.Width = barWidth; - bar.Left = Width - bar.Width - 1; - if (bar == null) - { - return; - } + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 2, ScrollBarWidth); + if (bar == null) return; + bar.Width = barWidth + 1; + bar.Left = Width - barWidth - 3; var si = ScrollBarInfo.GetInfo(edit.Handle); if (si.ScrollMax > 0) @@ -475,9 +492,10 @@ namespace Sunny.UI private void SizeChange() { + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 2, ScrollBarWidth); bar.Top = 2; - bar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1; - bar.Left = Width - bar.Width - 1; + bar.Width = barWidth + 1; + bar.Left = Width - barWidth - 3; bar.Height = Height - 4; bar.BringToFront(); SetScrollInfo(); diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index 5fee6ba7..fc7e72cb 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -54,6 +54,7 @@ * 2023-10-25: V3.5.1 修复在高DPI下,文字垂直不居中的问题 * 2023-10-25: V3.5.1 修复在某些字体不显示下划线的问题 * 2023-10-26: V3.5.1 字体图标增加旋转角度参数SymbolRotate + * 2023-11-16: V3.5.2 重构主题 ******************************************************************************/ using System; @@ -128,7 +129,6 @@ namespace Sunny.UI bar.Parent = this; bar.Dock = DockStyle.None; - bar.Style = UIStyle.Custom; bar.Visible = false; bar.ValueChanged += Bar_ValueChanged; bar.MouseEnter += Bar_MouseEnter; @@ -767,10 +767,10 @@ namespace Sunny.UI edit.Left = 4; edit.Width = Width - 8; - int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 1, ScrollBarWidth); + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 2, ScrollBarWidth); bar.Top = 2; - bar.Width = barWidth; - bar.Left = Width - bar.Width - 2; + bar.Width = barWidth + 1; + bar.Left = Width - barWidth - 3; bar.Height = Height - 4; bar.BringToFront(); @@ -920,7 +920,7 @@ namespace Sunny.UI edit.ForeColor = GetForeColor(); edit.ForeDisableColor = uiColor.ForeDisableColor; - if (bar != null) + if (bar != null && bar.Style == UIStyle.Inherited) { bar.ForeColor = uiColor.PrimaryColor; bar.HoverColor = uiColor.ButtonFillHoverColor; @@ -946,6 +946,25 @@ namespace Sunny.UI } } + /// + /// 滚动条主题样式 + /// + [DefaultValue(true), Description("滚动条主题样式"), Category("SunnyUI")] + public bool ScrollBarStyleInherited + { + get => bar != null && bar.Style == UIStyle.Inherited; + set + { + if (value) + { + if (bar != null) bar.Style = UIStyle.Inherited; + scrollBarColor = UIStyles.Blue.PrimaryColor; + scrollBarBackColor = UIStyles.Blue.EditorBackColor; + } + + } + } + protected override void SetForeDisableColor(Color color) { base.SetForeDisableColor(color); @@ -966,6 +985,7 @@ namespace Sunny.UI { scrollBarColor = value; bar.HoverColor = bar.PressColor = bar.ForeColor = value; + bar.Style = UIStyle.Custom; Invalidate(); } } @@ -984,7 +1004,7 @@ namespace Sunny.UI { scrollBarBackColor = value; bar.FillColor = value; - _style = UIStyle.Custom; + bar.Style = UIStyle.Custom; Invalidate(); } }