* UIEditForm:代码生成增加Switch类型
This commit is contained in:
parent
c91f03f3bd
commit
92f79234d2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -62,6 +62,7 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
option.AddDate("Birthday", "生日", DateTime.Now);
|
option.AddDate("Birthday", "生日", DateTime.Now);
|
||||||
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
||||||
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
||||||
|
option.AddSwitch("Switch", "选择", false);
|
||||||
|
|
||||||
UIEditForm frm = new UIEditForm(option);
|
UIEditForm frm = new UIEditForm(option);
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
@ -73,6 +74,7 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
Console.WriteLine("生日: " + frm["Birthday"]);
|
Console.WriteLine("生日: " + frm["Birthday"]);
|
||||||
Console.WriteLine("性别: " + sex[(int)frm["Sex"]]);
|
Console.WriteLine("性别: " + sex[(int)frm["Sex"]]);
|
||||||
Console.WriteLine("关联: " + frm["Info"]);
|
Console.WriteLine("关联: " + frm["Info"]);
|
||||||
|
Console.WriteLine("选择: " + frm["Switch"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
frm.Dispose();
|
frm.Dispose();
|
||||||
|
@ -57,7 +57,7 @@ namespace Sunny.UI
|
|||||||
fillColor = Color.White;
|
fillColor = Color.White;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UISwitchShape switchShape = UISwitchShape.Round;
|
private UISwitchShape switchShape = UISwitchShape.Round;
|
||||||
|
|
||||||
[Description("开关形状"), Category("SunnyUI")]
|
[Description("开关形状"), Category("SunnyUI")]
|
||||||
[DefaultValue(UISwitchShape.Round)]
|
[DefaultValue(UISwitchShape.Round)]
|
||||||
|
@ -164,6 +164,21 @@ namespace Sunny.UI
|
|||||||
ctrls.Add(edit);
|
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)
|
if (info.EditType == EditType.Combobox)
|
||||||
{
|
{
|
||||||
UIComboBox edit = new UIComboBox();
|
UIComboBox edit = new UIComboBox();
|
||||||
@ -349,6 +364,13 @@ namespace Sunny.UI
|
|||||||
if (edit == null) continue;
|
if (edit == null) continue;
|
||||||
info.Value = edit.ValueMember.IsValid() ? edit.SelectedValue : edit.SelectedIndex;
|
info.Value = edit.ValueMember.IsValid() ? edit.SelectedValue : edit.SelectedIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.EditType == EditType.Switch)
|
||||||
|
{
|
||||||
|
UISwitch edit = this.GetControl<UISwitch>("Edit_" + info.DataPropertyName);
|
||||||
|
if (edit == null) continue;
|
||||||
|
info.Value = edit.Active;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ namespace Sunny.UI
|
|||||||
Date,
|
Date,
|
||||||
DateTime,
|
DateTime,
|
||||||
Password,
|
Password,
|
||||||
Combobox
|
Combobox,
|
||||||
|
Switch
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EditInfo
|
public class EditInfo
|
||||||
@ -187,6 +188,24 @@ namespace Sunny.UI
|
|||||||
Dictionary.TryAdd(info.DataPropertyName, info);
|
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,
|
public void AddCombobox(string dataPropertyName, string text, IList dataSource, string displayMember,
|
||||||
string valueMember, object value, bool enabled = true, bool halfWidth = false)
|
string valueMember, object value, bool enabled = true, bool halfWidth = false)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user