* UIEditForm: 代码创建时增加UISwitch开关文字描述
This commit is contained in:
parent
56272f7ada
commit
e47df1762b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -62,7 +62,7 @@ namespace Sunny.UI.Demo
|
||||
option.AddDate("Birthday", "生日", DateTime.Now);
|
||||
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
||||
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
||||
option.AddSwitch("Switch", "选择", false);
|
||||
option.AddSwitch("Switch", "选择", false, "打开", "关闭");
|
||||
|
||||
UIEditForm frm = new UIEditForm(option);
|
||||
frm.CheckedData += Frm_CheckedData;
|
||||
|
@ -178,6 +178,17 @@ namespace Sunny.UI
|
||||
edit.Parent = this;
|
||||
edit.Name = "Edit_" + info.DataPropertyName;
|
||||
edit.Enabled = info.Enabled;
|
||||
|
||||
if (info.DataSource != null)
|
||||
{
|
||||
string[] items = (string[])info.DataSource;
|
||||
edit.ActiveText = items[0];
|
||||
edit.InActiveText = items[1];
|
||||
SizeF sf1 = GDI.MeasureString(items[0], edit.Font);
|
||||
SizeF sf2 = GDI.MeasureString(items[0], edit.Font);
|
||||
edit.Width = (int)Math.Max(sf1.Width, sf2.Width) + edit.Height + 16;
|
||||
}
|
||||
|
||||
ctrls.Add(edit);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,9 @@ namespace Sunny.UI
|
||||
public bool HalfWidth { get; set; }
|
||||
|
||||
public object DataSource { get; set; }
|
||||
|
||||
public string DisplayMember { get; set; }
|
||||
|
||||
public string ValueMember { get; set; }
|
||||
}
|
||||
|
||||
@ -206,6 +208,25 @@ namespace Sunny.UI
|
||||
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||
}
|
||||
|
||||
public void AddSwitch(string dataPropertyName, string text, bool value, string activeText, string inActiveText, 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,
|
||||
DataSource = new string[2] { activeText, inActiveText }
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user