* UICheckBoxGroup,UIRadioButtonGroup:可以设置初始选中值

This commit is contained in:
Sunny 2020-07-04 22:27:04 +08:00
parent be01e1890c
commit 3b285175b6
12 changed files with 107 additions and 55 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -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);

View File

@ -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<int>() { 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<int>() { 2, 4 };
}
private void uiButton4_Click(object sender, EventArgs e)
{
uiCheckBoxGroup1.SelectedIndexes = new List<int>() { 2, 4 };

View File

@ -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);
}
}
}

View File

@ -1,23 +1,23 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@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 QQ17612584 EMailSunnyUI@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;
}
}
}
}
}

View File

@ -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;
}
}
}
}
}

View File

@ -152,9 +152,9 @@ namespace Sunny.UI
/// </summary>
public static class UIStyles
{
public static ListEx<UIStyle> PopularStyles()
public static List<UIStyle> PopularStyles()
{
ListEx<UIStyle> styles = new ListEx<UIStyle>();
List<UIStyle> styles = new List<UIStyle>();
foreach (UIStyle style in Enum.GetValues(typeof(UIStyle)))
{
if (style.Value() >= UIStyle.Blue.Value() && style.Value() <= UIStyle.Office2010Black.Value())

View File

@ -28,7 +28,7 @@ namespace Sunny.UI
/// 支持事件的List
/// </summary>
/// <typeparam name="T"></typeparam>
public class ListEx<T> : List<T> where T : new()
public class ListEx<T> : List<T>
{
public delegate void OnListChange(object sender, T item, int index);