* UICheckBoxGroup,UIRadioButtonGroup:可以设置初始选中值
This commit is contained in:
parent
be01e1890c
commit
3b285175b6
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
SunnyUI.Demo/Controls/FButton.Designer.cs
generated
1
SunnyUI.Demo/Controls/FButton.Designer.cs
generated
@ -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
|
||||
|
5
SunnyUI.Demo/Controls/FCheckBox.Designer.cs
generated
5
SunnyUI.Demo/Controls/FCheckBox.Designer.cs
generated
@ -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);
|
||||
|
||||
|
@ -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 };
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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())
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user