* UIEditForm: 代码生成增加ComboTreeView类型

This commit is contained in:
Sunny 2021-10-26 12:00:36 +08:00
parent 0a0a71e0da
commit de6fa5a9ba
6 changed files with 65 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms;
namespace Sunny.UI.Demo namespace Sunny.UI.Demo
{ {
@ -54,6 +55,16 @@ namespace Sunny.UI.Demo
string[] sex = new[] { "男", "女" }; string[] sex = new[] { "男", "女" };
TreeNode[] nodes = new TreeNode[3];
nodes[0] = new TreeNode("AA");
nodes[1] = new TreeNode("BB");
nodes[2] = new TreeNode("CC");
nodes[0].Nodes.Add("AA11");
nodes[0].Nodes.Add("AA22");
nodes[0].Nodes.Add("AA33");
nodes[1].Nodes.Add("BB11");
nodes[1].Nodes.Add("BB22");
UIEditOption option = new UIEditOption(); UIEditOption option = new UIEditOption();
option.AutoLabelWidth = true; option.AutoLabelWidth = true;
option.Text = "增加"; option.Text = "增加";
@ -63,6 +74,7 @@ namespace Sunny.UI.Demo
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, "打开", "关闭"); option.AddSwitch("Switch", "选择", false, "打开", "关闭");
option.AddComboTreeView("ComboTree", "选择", nodes, nodes[1].Nodes[1]);
UIEditForm frm = new UIEditForm(option); UIEditForm frm = new UIEditForm(option);
frm.CheckedData += Frm_CheckedData; frm.CheckedData += Frm_CheckedData;
@ -76,6 +88,7 @@ namespace Sunny.UI.Demo
Console.WriteLine("性别: " + sex[(int)frm["Sex"]]); Console.WriteLine("性别: " + sex[(int)frm["Sex"]]);
Console.WriteLine("关联: " + frm["Info"]); Console.WriteLine("关联: " + frm["Info"]);
Console.WriteLine("选择: " + frm["Switch"]); Console.WriteLine("选择: " + frm["Switch"]);
Console.WriteLine("选择: " + frm["ComboTree"]);
} }
frm.Dispose(); frm.Dispose();

View File

@ -209,7 +209,7 @@ namespace Sunny.UI
SizeF sf = g.MeasureString(Text, Font); SizeF sf = g.MeasureString(Text, Font);
if (Direction == LineDirection.Horizontal && Height > sf.Height) if (Direction == LineDirection.Horizontal)
{ {
switch (TextAlign) switch (TextAlign)
{ {

View File

@ -19,6 +19,7 @@
* 2020-01-01: V2.2.0 * 2020-01-01: V2.2.0
* 2021-04-26: V3.0.3 Switch类型Combobox类型 * 2021-04-26: V3.0.3 Switch类型Combobox类型
* 2021-05-19: V3.0.3 * 2021-05-19: V3.0.3
* 2021-10-26: V3.0.8 ComboTreeView类型
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -222,6 +223,25 @@ namespace Sunny.UI
edit.SelectedValue = info.Value; edit.SelectedValue = info.Value;
} }
ctrls.Add(edit);
}
if (info.EditType== EditType.ComboTreeView)
{
UIComboTreeView edit = new UIComboTreeView();
edit.CanSelectRootNode = true;
edit.ShowLines = true;
edit.DropDownStyle = UIDropDownStyle.DropDownList;
edit.Left = option.LabelWidth;
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
edit.Top = top;
edit.Parent = this;
edit.Name = "Edit_" + info.DataPropertyName;
edit.Enabled = info.Enabled;
edit.TreeView.Nodes.Clear();
edit.TreeView.Nodes.AddRange((TreeNode[])info.DataSource);
edit.TreeView.SelectedNode = (TreeNode)info.Value;
ctrls.Add(edit); ctrls.Add(edit);
} }
@ -399,6 +419,13 @@ namespace Sunny.UI
if (edit == null) continue; if (edit == null) continue;
info.Value = edit.Active; info.Value = edit.Active;
} }
if (info.EditType == EditType.ComboTreeView)
{
UIComboTreeView edit = this.GetControl<UIComboTreeView>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
info.Value = edit.TreeView.SelectedNode;
}
} }
} }

View File

@ -24,6 +24,7 @@ using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
{ {
@ -36,7 +37,9 @@ namespace Sunny.UI
DateTime, DateTime,
Password, Password,
Combobox, Combobox,
Switch Switch,
ComboTreeView
} }
public class EditInfo public class EditInfo
@ -269,5 +272,25 @@ namespace Sunny.UI
Infos.Add(info); Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info); Dictionary.TryAdd(info.DataPropertyName, info);
} }
public void AddComboTreeView(string dataPropertyName, string text, TreeNode[] nodes, TreeNode value, bool enabled = true, bool halfWidth = false)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.ComboTreeView,
Text = text,
Value = value,
Enabled = enabled,
HalfWidth = halfWidth,
DataSource = nodes
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
} }
} }