diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index 384e4593..a3c875a2 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 7cc3ee24..936d8d3a 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/SunnyUI.dll b/Bin/net5.0-windows/SunnyUI.dll index 71f8457f..428cfb9b 100644 Binary files a/Bin/net5.0-windows/SunnyUI.dll and b/Bin/net5.0-windows/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/ref/SunnyUI.dll b/Bin/net5.0-windows/ref/SunnyUI.dll index 209a44ca..5c129b1a 100644 Binary files a/Bin/net5.0-windows/ref/SunnyUI.dll and b/Bin/net5.0-windows/ref/SunnyUI.dll differ diff --git a/Bin/netcoreapp3.1/SunnyUI.dll b/Bin/netcoreapp3.1/SunnyUI.dll index cb0ffc01..ad00b2ba 100644 Binary files a/Bin/netcoreapp3.1/SunnyUI.dll and b/Bin/netcoreapp3.1/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Forms/FEditor.cs b/SunnyUI.Demo/Forms/FEditor.cs index 896ac0ab..1acc7c6a 100644 --- a/SunnyUI.Demo/Forms/FEditor.cs +++ b/SunnyUI.Demo/Forms/FEditor.cs @@ -62,6 +62,7 @@ namespace Sunny.UI.Demo.Forms option.AddDate("Birthday", "生日", DateTime.Now); option.AddCombobox("Sex", "性别", sex, 1, true, true); option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2"); + option.AddSwitch("Switch", "选择", false); UIEditForm frm = new UIEditForm(option); frm.ShowDialog(); @@ -73,6 +74,7 @@ namespace Sunny.UI.Demo.Forms Console.WriteLine("生日: " + frm["Birthday"]); Console.WriteLine("性别: " + sex[(int)frm["Sex"]]); Console.WriteLine("关联: " + frm["Info"]); + Console.WriteLine("选择: " + frm["Switch"]); } frm.Dispose(); diff --git a/SunnyUI/Controls/UISwitch.cs b/SunnyUI/Controls/UISwitch.cs index b598d82d..b74c7aa6 100644 --- a/SunnyUI/Controls/UISwitch.cs +++ b/SunnyUI/Controls/UISwitch.cs @@ -57,7 +57,7 @@ namespace Sunny.UI fillColor = Color.White; } - public UISwitchShape switchShape = UISwitchShape.Round; + private UISwitchShape switchShape = UISwitchShape.Round; [Description("开关形状"), Category("SunnyUI")] [DefaultValue(UISwitchShape.Round)] diff --git a/SunnyUI/Forms/UIEditForm.cs b/SunnyUI/Forms/UIEditForm.cs index 3cffe630..cd9b0a2c 100644 --- a/SunnyUI/Forms/UIEditForm.cs +++ b/SunnyUI/Forms/UIEditForm.cs @@ -164,6 +164,21 @@ namespace Sunny.UI ctrls.Add(edit); } + if (info.EditType == EditType.Switch) + { + UISwitch edit = new UISwitch(); + edit.SwitchShape = UISwitch.UISwitchShape.Square; + edit.Left = option.LabelWidth; + edit.Width = 75; + edit.Height = 29; + edit.Top = top; + edit.Active = (bool)info.Value; + edit.Parent = this; + edit.Name = "Edit_" + info.DataPropertyName; + edit.Enabled = info.Enabled; + ctrls.Add(edit); + } + if (info.EditType == EditType.Combobox) { UIComboBox edit = new UIComboBox(); @@ -349,6 +364,13 @@ namespace Sunny.UI if (edit == null) continue; info.Value = edit.ValueMember.IsValid() ? edit.SelectedValue : edit.SelectedIndex; } + + if (info.EditType == EditType.Switch) + { + UISwitch edit = this.GetControl("Edit_" + info.DataPropertyName); + if (edit == null) continue; + info.Value = edit.Active; + } } } diff --git a/SunnyUI/Forms/UIEditFormHelper.cs b/SunnyUI/Forms/UIEditFormHelper.cs index 006bee6c..300f1fb8 100644 --- a/SunnyUI/Forms/UIEditFormHelper.cs +++ b/SunnyUI/Forms/UIEditFormHelper.cs @@ -35,7 +35,8 @@ namespace Sunny.UI Date, DateTime, Password, - Combobox + Combobox, + Switch } public class EditInfo @@ -187,6 +188,24 @@ namespace Sunny.UI Dictionary.TryAdd(info.DataPropertyName, info); } + public void AddSwitch(string dataPropertyName, string text, bool value, bool enabled = true) + { + if (Dictionary.ContainsKey(dataPropertyName)) + throw new DuplicateNameException(dataPropertyName + ": 已经存在"); + + EditInfo info = new EditInfo() + { + DataPropertyName = dataPropertyName, + EditType = EditType.Switch, + Text = text, + Value = value, + Enabled = enabled + }; + + Infos.Add(info); + Dictionary.TryAdd(info.DataPropertyName, info); + } + public void AddCombobox(string dataPropertyName, string text, IList dataSource, string displayMember, string valueMember, object value, bool enabled = true, bool halfWidth = false) {