diff --git a/Bin/SunnyUI.dll b/Bin/SunnyUI.dll index 3f2d81f9..14931c79 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/Bin/SunnyUI.pdb b/Bin/SunnyUI.pdb index ad20fe52..8cbb752e 100644 Binary files a/Bin/SunnyUI.pdb and b/Bin/SunnyUI.pdb differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe index 920940a0..2e4d049e 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe and b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.dll b/SunnyUI.Demo/Bin/SunnyUI.dll index 3f2d81f9..14931c79 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.dll and b/SunnyUI.Demo/Bin/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FButton.Designer.cs b/SunnyUI.Demo/Controls/FButton.Designer.cs index 249e4bf2..5adfc1a9 100644 --- a/SunnyUI.Demo/Controls/FButton.Designer.cs +++ b/SunnyUI.Demo/Controls/FButton.Designer.cs @@ -144,6 +144,7 @@ this.PagePanel.Controls.Add(this.uiButton2); this.PagePanel.Controls.Add(this.uiButton1); this.PagePanel.Size = new System.Drawing.Size(800, 499); + this.PagePanel.Style = Sunny.UI.UIStyle.Blue; this.PagePanel.Text = ""; // // uiButton1 diff --git a/SunnyUI.Demo/Controls/FCheckBox.Designer.cs b/SunnyUI.Demo/Controls/FCheckBox.Designer.cs index 6c1e03b2..fbcb5bd7 100644 --- a/SunnyUI.Demo/Controls/FCheckBox.Designer.cs +++ b/SunnyUI.Demo/Controls/FCheckBox.Designer.cs @@ -128,7 +128,9 @@ "5", "6", "7", - "8"}); + "8", + "9"}); + this.uiCheckBoxGroup1.ItemSize = new System.Drawing.Size(110, 35); this.uiCheckBoxGroup1.Location = new System.Drawing.Point(30, 91); this.uiCheckBoxGroup1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.uiCheckBoxGroup1.Name = "uiCheckBoxGroup1"; @@ -191,7 +193,6 @@ this.Name = "FCheckBox"; this.Symbol = 61770; this.Text = "CheckBox"; - this.Shown += new System.EventHandler(this.FCheckBox_Shown); this.PagePanel.ResumeLayout(false); this.ResumeLayout(false); diff --git a/SunnyUI.Demo/Controls/FCheckBox.cs b/SunnyUI.Demo/Controls/FCheckBox.cs index 0f0a344f..e451f6c1 100644 --- a/SunnyUI.Demo/Controls/FCheckBox.cs +++ b/SunnyUI.Demo/Controls/FCheckBox.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using System.Windows.Forms; namespace Sunny.UI.Demo { @@ -10,6 +9,7 @@ namespace Sunny.UI.Demo public FCheckBox() { InitializeComponent(); + uiCheckBoxGroup1.SelectedIndexes = new List() { 2, 4 }; } private void uiCheckBoxGroup1_ValueChanged(object sender, int index, string text, bool isChecked) @@ -22,7 +22,7 @@ namespace Sunny.UI.Demo sb.Append(", "); } - this.ShowSuccessTip("SelectedIndex: " + index + ", SelectedText: " + text + "\n" + sb.ToString()); + Console.WriteLine("SelectedIndex: " + index + ", SelectedText: " + text + "\n" + sb.ToString()); } private void uiButton1_Click(object sender, System.EventArgs e) @@ -40,11 +40,6 @@ namespace Sunny.UI.Demo uiCheckBoxGroup1.ReverseSelected(); } - private void FCheckBox_Shown(object sender, EventArgs e) - { - uiCheckBoxGroup1.SelectedIndexes = new List() { 2, 4 }; - } - private void uiButton4_Click(object sender, EventArgs e) { uiCheckBoxGroup1.SelectedIndexes = new List() { 2, 4 }; diff --git a/SunnyUI.Demo/Controls/FRadioButton.cs b/SunnyUI.Demo/Controls/FRadioButton.cs index 6a926c2a..53677b78 100644 --- a/SunnyUI.Demo/Controls/FRadioButton.cs +++ b/SunnyUI.Demo/Controls/FRadioButton.cs @@ -1,15 +1,18 @@ -namespace Sunny.UI.Demo +using System; + +namespace Sunny.UI.Demo { public partial class FRadioButton : UITitlePage { public FRadioButton() { InitializeComponent(); + uiRadioButtonGroup1.SelectedIndex = 2; } private void uiRadioButtonGroup1_ValueChanged(object sender, int index, string text) { - this.ShowInfoDialog("SelectedIndex: " + index + ", SelectedText: " + text); + Console.WriteLine("SelectedIndex: " + index + ", SelectedText: " + text); } } } \ No newline at end of file diff --git a/SunnyUI/Controls/UICheckBoxGroup.cs b/SunnyUI/Controls/UICheckBoxGroup.cs index f2445b52..d16f5e86 100644 --- a/SunnyUI/Controls/UICheckBoxGroup.cs +++ b/SunnyUI/Controls/UICheckBoxGroup.cs @@ -1,23 +1,23 @@ /****************************************************************************** - * SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。 - * CopyRight (C) 2012-2020 ShenYongHua(沈永华). - * QQ群:56829229 QQ:17612584 EMail:SunnyUI@qq.com - * - * Blog: https://www.cnblogs.com/yhuse - * Gitee: https://gitee.com/yhuse/SunnyUI - * GitHub: https://github.com/yhuse/SunnyUI - * - * SunnyUI.dll can be used for free under the GPL-3.0 license. - * If you use this code, please keep this note. - * 如果您使用此代码,请保留此说明。 - ****************************************************************************** - * 文件名称: UICheckBoxGroup.cs - * 文件说明: 多选框组 - * 当前版本: V2.2 - * 创建日期: 2020-01-01 - * - * 2020-04-19: V2.2.3 增加单元 - * 2020-04-25: V2.2.4 更新主题配置类 +* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。 +* CopyRight (C) 2012-2020 ShenYongHua(沈永华). +* QQ群:56829229 QQ:17612584 EMail:SunnyUI@qq.com +* +* Blog: https://www.cnblogs.com/yhuse +* Gitee: https://gitee.com/yhuse/SunnyUI +* GitHub: https://github.com/yhuse/SunnyUI +* +* SunnyUI.dll can be used for free under the GPL-3.0 license. +* If you use this code, please keep this note. +* 如果您使用此代码,请保留此说明。 +****************************************************************************** +* 文件名称: UICheckBoxGroup.cs +* 文件说明: 多选框组 +* 当前版本: V2.2 +* 创建日期: 2020-01-01 +* +* 2020-04-19: V2.2.3 增加单元 +* 2020-04-25: V2.2.4 更新主题配置类 ******************************************************************************/ using System; @@ -70,33 +70,33 @@ namespace Sunny.UI boxes.Clear(); } - private void Listbox_DrawItemEx(object sender, ListBox.ObjectCollection items, DrawItemEventArgs e) - { - Invalidate(); - } - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Localizable(true)] [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] [MergableProperty(false)] public ListBox.ObjectCollection Items => ListBox.Items; - private ListBoxEx listbox; + private CheckedListBoxEx listbox; - private ListBoxEx ListBox + private CheckedListBoxEx ListBox { get { if (listbox == null) { - listbox = new ListBoxEx(); - listbox.BeforeDrawItem += Listbox_DrawItemEx; + listbox = new CheckedListBoxEx(); + listbox.OnItemsCountChange += Listbox_OnItemsCountChange; } return listbox; } } + private void Listbox_OnItemsCountChange(object sender, EventArgs e) + { + Invalidate(); + } + private void CreateBoxes() { if (Items.Count == 0) return; @@ -171,7 +171,11 @@ namespace Sunny.UI } set { - if (boxes.Count==0) return; + if (boxes.Count != Items.Count) + { + CreateBoxes(); + } + foreach (int i in value) { if (i >= 0 && i < boxes.Count) @@ -318,5 +322,24 @@ namespace Sunny.UI } private bool multiChange; + + [ToolboxItem(false)] + internal class CheckedListBoxEx : CheckedListBox + { + public event EventHandler OnItemsCountChange; + + private int count = -1; + + protected override void OnDrawItem(DrawItemEventArgs e) + { + base.OnDrawItem(e); + + if (count != Items.Count) + { + OnItemsCountChange?.Invoke(this, e); + count = Items.Count; + } + } + } } } \ No newline at end of file diff --git a/SunnyUI/Controls/UIRadioButtonGroup.cs b/SunnyUI/Controls/UIRadioButtonGroup.cs index 8a4fd83b..b47f1bbd 100644 --- a/SunnyUI/Controls/UIRadioButtonGroup.cs +++ b/SunnyUI/Controls/UIRadioButtonGroup.cs @@ -54,37 +54,35 @@ namespace Sunny.UI buttons.Clear(); } - private void Listbox_DrawItemEx(object sender, ListBox.ObjectCollection items, DrawItemEventArgs e) - { - Invalidate(); - } - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Localizable(true)] [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] [MergableProperty(false)] public ListBox.ObjectCollection Items => ListBox.Items; - private ListBoxEx listbox; + private CheckedListBoxEx listbox; - private ListBoxEx ListBox + private CheckedListBoxEx ListBox { get { if (listbox == null) { - listbox = new ListBoxEx(); - listbox.BeforeDrawItem += Listbox_DrawItemEx; + listbox = new CheckedListBoxEx(); + listbox.OnItemsCountChange += Listbox_OnItemsCountChange; } return listbox; } } - protected override void OnPaint(PaintEventArgs e) + private void Listbox_OnItemsCountChange(object sender, EventArgs e) { - base.OnPaint(e); + Invalidate(); + } + private void CreateBoxes() + { if (Items.Count == 0) return; if (Items.Count != buttons.Count) { @@ -105,6 +103,13 @@ namespace Sunny.UI buttons.Add(button); } } + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + CreateBoxes(); int startX = StartPos.X; int startY = TitleTop + StartPos.Y; @@ -138,7 +143,12 @@ namespace Sunny.UI get => ListBox.SelectedIndex; set { - if (ListBox.Count == 0) + if (buttons.Count != Items.Count) + { + CreateBoxes(); + } + + if (Items.Count == 0) { ListBox.SelectedIndex = -1; return; @@ -231,5 +241,24 @@ namespace Sunny.UI button.Font = Font; } } + + [ToolboxItem(false)] + internal class CheckedListBoxEx : CheckedListBox + { + public event EventHandler OnItemsCountChange; + + private int count = -1; + + protected override void OnDrawItem(DrawItemEventArgs e) + { + base.OnDrawItem(e); + + if (count != Items.Count) + { + OnItemsCountChange?.Invoke(this, e); + count = Items.Count; + } + } + } } } \ No newline at end of file diff --git a/SunnyUI/Style/UIStyle.cs b/SunnyUI/Style/UIStyle.cs index 9576c538..1243e265 100644 --- a/SunnyUI/Style/UIStyle.cs +++ b/SunnyUI/Style/UIStyle.cs @@ -152,9 +152,9 @@ namespace Sunny.UI /// public static class UIStyles { - public static ListEx PopularStyles() + public static List PopularStyles() { - ListEx styles = new ListEx(); + List styles = new List(); foreach (UIStyle style in Enum.GetValues(typeof(UIStyle))) { if (style.Value() >= UIStyle.Blue.Value() && style.Value() <= UIStyle.Office2010Black.Value()) diff --git a/SunnyUI/Units/UListEx.cs b/SunnyUI/Units/UListEx.cs index 2466430c..a4f312bd 100644 --- a/SunnyUI/Units/UListEx.cs +++ b/SunnyUI/Units/UListEx.cs @@ -28,7 +28,7 @@ namespace Sunny.UI /// 支持事件的List /// /// - public class ListEx : List where T : new() + public class ListEx : List { public delegate void OnListChange(object sender, T item, int index);