* UIEditForm:新增可通过代码创建编辑表单窗体

* UICombobox:增加下拉框宽度
This commit is contained in:
Sunny 2020-12-28 23:18:33 +08:00
parent 4acbbabb53
commit d316efc1d3
12 changed files with 660 additions and 131 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,54 +28,54 @@
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.TreeNode treeNode61 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode62 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode63 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode64 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode57 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode58 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode59 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode60 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode33 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode34 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode35 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode36 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode37 = new System.Windows.Forms.TreeNode("节点0", new System.Windows.Forms.TreeNode[] {
treeNode33,
treeNode34,
treeNode35,
treeNode36});
System.Windows.Forms.TreeNode treeNode38 = new System.Windows.Forms.TreeNode("节点4");
System.Windows.Forms.TreeNode treeNode39 = new System.Windows.Forms.TreeNode("节点5");
System.Windows.Forms.TreeNode treeNode40 = new System.Windows.Forms.TreeNode("节点6");
System.Windows.Forms.TreeNode treeNode41 = new System.Windows.Forms.TreeNode("节点7");
System.Windows.Forms.TreeNode treeNode42 = new System.Windows.Forms.TreeNode("节点1", new System.Windows.Forms.TreeNode[] {
treeNode38,
treeNode39,
treeNode40,
treeNode41});
System.Windows.Forms.TreeNode treeNode43 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode44 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode45 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode46 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode47 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode48 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode49 = new System.Windows.Forms.TreeNode("节点0", new System.Windows.Forms.TreeNode[] {
treeNode45,
treeNode46,
treeNode47,
treeNode48});
System.Windows.Forms.TreeNode treeNode50 = new System.Windows.Forms.TreeNode("节点4");
System.Windows.Forms.TreeNode treeNode51 = new System.Windows.Forms.TreeNode("节点5");
System.Windows.Forms.TreeNode treeNode52 = new System.Windows.Forms.TreeNode("节点6");
System.Windows.Forms.TreeNode treeNode53 = new System.Windows.Forms.TreeNode("节点7");
System.Windows.Forms.TreeNode treeNode54 = new System.Windows.Forms.TreeNode("节点1", new System.Windows.Forms.TreeNode[] {
treeNode50,
treeNode51,
treeNode52,
treeNode53});
System.Windows.Forms.TreeNode treeNode55 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode56 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode29 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode30 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode31 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode32 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode25 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode26 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode27 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode28 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode5 = new System.Windows.Forms.TreeNode("节点0", new System.Windows.Forms.TreeNode[] {
treeNode1,
treeNode2,
treeNode3,
treeNode4});
System.Windows.Forms.TreeNode treeNode6 = new System.Windows.Forms.TreeNode("节点4");
System.Windows.Forms.TreeNode treeNode7 = new System.Windows.Forms.TreeNode("节点5");
System.Windows.Forms.TreeNode treeNode8 = new System.Windows.Forms.TreeNode("节点6");
System.Windows.Forms.TreeNode treeNode9 = new System.Windows.Forms.TreeNode("节点7");
System.Windows.Forms.TreeNode treeNode10 = new System.Windows.Forms.TreeNode("节点1", new System.Windows.Forms.TreeNode[] {
treeNode6,
treeNode7,
treeNode8,
treeNode9});
System.Windows.Forms.TreeNode treeNode11 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode12 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode13 = new System.Windows.Forms.TreeNode("节点0");
System.Windows.Forms.TreeNode treeNode14 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode15 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode16 = new System.Windows.Forms.TreeNode("节点3");
System.Windows.Forms.TreeNode treeNode17 = new System.Windows.Forms.TreeNode("节点0", new System.Windows.Forms.TreeNode[] {
treeNode13,
treeNode14,
treeNode15,
treeNode16});
System.Windows.Forms.TreeNode treeNode18 = new System.Windows.Forms.TreeNode("节点4");
System.Windows.Forms.TreeNode treeNode19 = new System.Windows.Forms.TreeNode("节点5");
System.Windows.Forms.TreeNode treeNode20 = new System.Windows.Forms.TreeNode("节点6");
System.Windows.Forms.TreeNode treeNode21 = new System.Windows.Forms.TreeNode("节点7");
System.Windows.Forms.TreeNode treeNode22 = new System.Windows.Forms.TreeNode("节点1", new System.Windows.Forms.TreeNode[] {
treeNode18,
treeNode19,
treeNode20,
treeNode21});
System.Windows.Forms.TreeNode treeNode23 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode24 = new System.Windows.Forms.TreeNode("节点3");
this.uiLine8 = new Sunny.UI.UILine();
this.uiDatetimePicker1 = new Sunny.UI.UIDatetimePicker();
this.uiColorPicker1 = new Sunny.UI.UIColorPicker();
@ -248,6 +248,7 @@
// uiComboBox2
//
this.uiComboBox2.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiComboBox2.DropDownWidth = 300;
this.uiComboBox2.FillColor = System.Drawing.Color.White;
this.uiComboBox2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboBox2.Items.AddRange(new object[] {
@ -297,19 +298,19 @@
this.uiComboTreeView1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView1.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView1.Name = "uiComboTreeView1";
treeNode61.Name = "节点0";
treeNode61.Text = "节点0";
treeNode62.Name = "节点1";
treeNode62.Text = "节点1";
treeNode63.Name = "节点2";
treeNode63.Text = "节点2";
treeNode64.Name = "节点3";
treeNode64.Text = "节点3";
treeNode29.Name = "节点0";
treeNode29.Text = "节点0";
treeNode30.Name = "节点1";
treeNode30.Text = "节点1";
treeNode31.Name = "节点2";
treeNode31.Text = "节点2";
treeNode32.Name = "节点3";
treeNode32.Text = "节点3";
this.uiComboTreeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode61,
treeNode62,
treeNode63,
treeNode64});
treeNode29,
treeNode30,
treeNode31,
treeNode32});
this.uiComboTreeView1.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiComboTreeView1.Size = new System.Drawing.Size(150, 29);
this.uiComboTreeView1.TabIndex = 43;
@ -337,19 +338,19 @@
this.uiComboTreeView2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView2.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView2.Name = "uiComboTreeView2";
treeNode57.Name = "节点0";
treeNode57.Text = "节点0";
treeNode58.Name = "节点1";
treeNode58.Text = "节点1";
treeNode59.Name = "节点2";
treeNode59.Text = "节点2";
treeNode60.Name = "节点3";
treeNode60.Text = "节点3";
treeNode25.Name = "节点0";
treeNode25.Text = "节点0";
treeNode26.Name = "节点1";
treeNode26.Text = "节点1";
treeNode27.Name = "节点2";
treeNode27.Text = "节点2";
treeNode28.Name = "节点3";
treeNode28.Text = "节点3";
this.uiComboTreeView2.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode57,
treeNode58,
treeNode59,
treeNode60});
treeNode25,
treeNode26,
treeNode27,
treeNode28});
this.uiComboTreeView2.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiComboTreeView2.Size = new System.Drawing.Size(150, 29);
this.uiComboTreeView2.TabIndex = 46;
@ -366,35 +367,35 @@
this.uiComboTreeView3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView3.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView3.Name = "uiComboTreeView3";
treeNode33.Name = "节点0";
treeNode33.Text = "节点0";
treeNode34.Name = "节点1";
treeNode34.Text = "节点1";
treeNode35.Name = "节点2";
treeNode35.Text = "节点2";
treeNode36.Name = "节点3";
treeNode36.Text = "节点3";
treeNode37.Name = "节点0";
treeNode37.Text = "节点0";
treeNode38.Name = "节点4";
treeNode38.Text = "节点4";
treeNode39.Name = "节点5";
treeNode39.Text = "节点5";
treeNode40.Name = "节点6";
treeNode40.Text = "节点6";
treeNode41.Name = "节点7";
treeNode41.Text = "节点7";
treeNode42.Name = "节点1";
treeNode42.Text = "节点1";
treeNode43.Name = "节点2";
treeNode43.Text = "节点2";
treeNode44.Name = "节点3";
treeNode44.Text = "节点3";
treeNode1.Name = "节点0";
treeNode1.Text = "节点0";
treeNode2.Name = "节点1";
treeNode2.Text = "节点1";
treeNode3.Name = "节点2";
treeNode3.Text = "节点2";
treeNode4.Name = "节点3";
treeNode4.Text = "节点3";
treeNode5.Name = "节点0";
treeNode5.Text = "节点0";
treeNode6.Name = "节点4";
treeNode6.Text = "节点4";
treeNode7.Name = "节点5";
treeNode7.Text = "节点5";
treeNode8.Name = "节点6";
treeNode8.Text = "节点6";
treeNode9.Name = "节点7";
treeNode9.Text = "节点7";
treeNode10.Name = "节点1";
treeNode10.Text = "节点1";
treeNode11.Name = "节点2";
treeNode11.Text = "节点2";
treeNode12.Name = "节点3";
treeNode12.Text = "节点3";
this.uiComboTreeView3.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode37,
treeNode42,
treeNode43,
treeNode44});
treeNode5,
treeNode10,
treeNode11,
treeNode12});
this.uiComboTreeView3.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiComboTreeView3.ShowLines = true;
this.uiComboTreeView3.Size = new System.Drawing.Size(150, 29);
@ -410,35 +411,35 @@
this.uiComboTreeView4.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView4.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView4.Name = "uiComboTreeView4";
treeNode45.Name = "节点0";
treeNode45.Text = "节点0";
treeNode46.Name = "节点1";
treeNode46.Text = "节点1";
treeNode47.Name = "节点2";
treeNode47.Text = "节点2";
treeNode48.Name = "节点3";
treeNode48.Text = "节点3";
treeNode49.Name = "节点0";
treeNode49.Text = "节点0";
treeNode50.Name = "节点4";
treeNode50.Text = "节点4";
treeNode51.Name = "节点5";
treeNode51.Text = "节点5";
treeNode52.Name = "节点6";
treeNode52.Text = "节点6";
treeNode53.Name = "节点7";
treeNode53.Text = "节点7";
treeNode54.Name = "节点1";
treeNode54.Text = "节点1";
treeNode55.Name = "节点2";
treeNode55.Text = "节点2";
treeNode56.Name = "节点3";
treeNode56.Text = "节点3";
treeNode13.Name = "节点0";
treeNode13.Text = "节点0";
treeNode14.Name = "节点1";
treeNode14.Text = "节点1";
treeNode15.Name = "节点2";
treeNode15.Text = "节点2";
treeNode16.Name = "节点3";
treeNode16.Text = "节点3";
treeNode17.Name = "节点0";
treeNode17.Text = "节点0";
treeNode18.Name = "节点4";
treeNode18.Text = "节点4";
treeNode19.Name = "节点5";
treeNode19.Text = "节点5";
treeNode20.Name = "节点6";
treeNode20.Text = "节点6";
treeNode21.Name = "节点7";
treeNode21.Text = "节点7";
treeNode22.Name = "节点1";
treeNode22.Text = "节点1";
treeNode23.Name = "节点2";
treeNode23.Text = "节点2";
treeNode24.Name = "节点3";
treeNode24.Text = "节点3";
this.uiComboTreeView4.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode49,
treeNode54,
treeNode55,
treeNode56});
treeNode17,
treeNode22,
treeNode23,
treeNode24});
this.uiComboTreeView4.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiComboTreeView4.ShowLines = true;
this.uiComboTreeView4.Size = new System.Drawing.Size(150, 29);

View File

@ -31,11 +31,15 @@
this.btnEdit = new Sunny.UI.UISymbolButton();
this.uiLine1 = new Sunny.UI.UILine();
this.btnAdd = new Sunny.UI.UISymbolButton();
this.uiSymbolButton1 = new Sunny.UI.UISymbolButton();
this.uiLine2 = new Sunny.UI.UILine();
this.PagePanel.SuspendLayout();
this.SuspendLayout();
//
// PagePanel
//
this.PagePanel.Controls.Add(this.uiLine2);
this.PagePanel.Controls.Add(this.uiSymbolButton1);
this.PagePanel.Controls.Add(this.btnAdd);
this.PagePanel.Controls.Add(this.uiLine1);
this.PagePanel.Controls.Add(this.btnEdit);
@ -45,6 +49,7 @@
this.btnEdit.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnEdit.Font = new System.Drawing.Font("微软雅黑", 12F);
this.btnEdit.Location = new System.Drawing.Point(152, 57);
this.btnEdit.MinimumSize = new System.Drawing.Size(1, 1);
this.btnEdit.Name = "btnEdit";
this.btnEdit.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.btnEdit.Size = new System.Drawing.Size(100, 35);
@ -69,6 +74,7 @@
this.btnAdd.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnAdd.Font = new System.Drawing.Font("微软雅黑", 12F);
this.btnAdd.Location = new System.Drawing.Point(30, 57);
this.btnAdd.MinimumSize = new System.Drawing.Size(1, 1);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.btnAdd.Size = new System.Drawing.Size(100, 35);
@ -77,6 +83,31 @@
this.btnAdd.Text = "增加";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// uiSymbolButton1
//
this.uiSymbolButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiSymbolButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiSymbolButton1.Location = new System.Drawing.Point(30, 149);
this.uiSymbolButton1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiSymbolButton1.Name = "uiSymbolButton1";
this.uiSymbolButton1.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.uiSymbolButton1.Size = new System.Drawing.Size(100, 35);
this.uiSymbolButton1.Symbol = 61543;
this.uiSymbolButton1.TabIndex = 21;
this.uiSymbolButton1.Text = "增加";
this.uiSymbolButton1.Click += new System.EventHandler(this.uiSymbolButton1_Click);
//
// uiLine2
//
this.uiLine2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine2.Location = new System.Drawing.Point(30, 114);
this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine2.Name = "uiLine2";
this.uiLine2.Size = new System.Drawing.Size(670, 20);
this.uiLine2.TabIndex = 22;
this.uiLine2.Text = "UIEditForm 代码生成";
this.uiLine2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// FEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
@ -95,5 +126,7 @@
private UISymbolButton btnEdit;
private UILine uiLine1;
private UISymbolButton btnAdd;
private UILine uiLine2;
private UISymbolButton uiSymbolButton1;
}
}

View File

@ -40,6 +40,28 @@ namespace Sunny.UI.Demo.Forms
frm.Dispose();
}
private void uiSymbolButton1_Click(object sender, EventArgs e)
{
UIEditOption option = new UIEditOption();
option.AutoLabelWidth = true;
option.Text = "增加";
option.AddText("Name", "姓名", "", true);
option.AddInteger("Age", "年龄", 20);
option.AddDate("Birthday", "生日", DateTime.Now);
UIEditForm frm = new UIEditForm(option);
frm.ShowDialog();
if (frm.IsOK)
{
Console.WriteLine("姓名: " + frm["Name"]);
Console.WriteLine("年龄: " + frm["Age"]);
Console.WriteLine("生日: " + frm["Birthday"]);
}
frm.Dispose();
}
}
public class Person

View File

@ -33,6 +33,7 @@ namespace Sunny.UI
/// 圆角位置
/// </summary>
[ComVisible(true)]
[ToolboxItem(false)]
[Editor(typeof(UIRadiusSidesEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Flags]
public enum UICornerRadiusSides

View File

@ -43,6 +43,7 @@ namespace Sunny.UI
box.DataSourceChanged += Box_DataSourceChanged;
box.DisplayMemberChanged += Box_DisplayMemberChanged;
box.ValueMemberChanged += Box_ValueMemberChanged;
DropDownWidth = 150;
}
private void Box_ValueMemberChanged(object sender, EventArgs e)
@ -139,7 +140,7 @@ namespace Sunny.UI
}
ListBox.SelectedIndex = SelectedIndex;
ItemForm.Show(this, new Size(Width, CalcItemFormHeight()));
ItemForm.Show(this, new Size(DropDownWidth < Width ? Width : DropDownWidth, CalcItemFormHeight()));
}
public override void SetStyleColor(UIBaseStyle uiColor)
@ -206,7 +207,9 @@ namespace Sunny.UI
}
}
//public int DropDownWidth { get; set; }
[DefaultValue(150)]
[Description("下拉框宽度"), Category("SunnyUI")]
public int DropDownWidth { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]

View File

@ -43,6 +43,7 @@
this.pnlBtm.Font = new System.Drawing.Font("微软雅黑", 12F);
this.pnlBtm.Location = new System.Drawing.Point(1, 392);
this.pnlBtm.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.pnlBtm.MinimumSize = new System.Drawing.Size(1, 1);
this.pnlBtm.Name = "pnlBtm";
this.pnlBtm.RadiusSides = Sunny.UI.UICornerRadiusSides.None;
this.pnlBtm.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Top;
@ -57,6 +58,7 @@
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 12F);
this.btnCancel.Location = new System.Drawing.Point(470, 12);
this.btnCancel.Margin = new System.Windows.Forms.Padding(0);
this.btnCancel.MinimumSize = new System.Drawing.Size(1, 1);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.btnCancel.Size = new System.Drawing.Size(100, 35);
@ -73,6 +75,7 @@
this.btnOK.Font = new System.Drawing.Font("微软雅黑", 12F);
this.btnOK.Location = new System.Drawing.Point(355, 12);
this.btnOK.Margin = new System.Windows.Forms.Padding(0);
this.btnOK.MinimumSize = new System.Drawing.Size(1, 1);
this.btnOK.Name = "btnOK";
this.btnOK.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.btnOK.Size = new System.Drawing.Size(100, 35);
@ -90,7 +93,6 @@
this.MinimizeBox = false;
this.Name = "UIEditForm";
this.Padding = new System.Windows.Forms.Padding(1, 35, 1, 3);
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.Text = "UIEditForm";
this.pnlBtm.ResumeLayout(false);

View File

@ -21,6 +21,7 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Sunny.UI
@ -35,6 +36,135 @@ namespace Sunny.UI
btnCancel.Text = UILocalize.Cancel;
}
private readonly UIEditOption Option;
public UIEditForm(UIEditOption option)
{
InitializeComponent();
btnOK.Text = UILocalize.OK;
btnCancel.Text = UILocalize.Cancel;
Option = option;
if (option == null || option.Infos.Count == 0) return;
base.Text = option.Text;
int tabIndex = 0;
int top = 55;
if (option.AutoLabelWidth)
{
float size = 0;
foreach (var info in option.Infos)
{
SizeF sf = info.Text.MeasureString(UIFontColor.Font);
size = Math.Max(sf.Width, size);
}
option.LabelWidth = (int)size + 1 + 50;
}
Width = option.LabelWidth + option.ValueWidth + 28;
foreach (var info in option.Infos)
{
UILabel label = new UILabel();
label.Text = info.Text;
label.AutoSize = false;
label.Left = 5;
label.Width = option.LabelWidth - 25;
label.Height = 29;
label.Top = top;
label.TextAlign = ContentAlignment.MiddleRight;
label.Parent = this;
if (info.EditType == EditType.Text)
{
UITextBox edit = new UITextBox();
edit.Left = option.LabelWidth;
edit.Width = option.ValueWidth;
edit.Top = top;
edit.Text = info.Value.ToString();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
}
if (info.EditType == EditType.Integer)
{
UITextBox edit = new UITextBox();
edit.Type = UITextBox.UIEditType.Integer;
edit.Left = option.LabelWidth;
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
edit.Top = top;
edit.IntValue = info.Value.ToString().ToInt();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
}
if (info.EditType == EditType.Double)
{
UITextBox edit = new UITextBox();
edit.Type = UITextBox.UIEditType.Double;
edit.Left = option.LabelWidth;
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
edit.Top = top;
edit.DoubleValue = info.Value.ToString().ToDouble();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
}
if (info.EditType == EditType.Date)
{
UIDatePicker edit = new UIDatePicker();
edit.Left = option.LabelWidth;
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
edit.Top = top;
edit.Value = (DateTime)info.Value;
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
}
if (info.EditType == EditType.DateTime)
{
UIDatetimePicker edit = new UIDatetimePicker();
edit.Left = option.LabelWidth;
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
edit.Top = top;
edit.Value = (DateTime)info.Value;
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
}
top += 29 + 10;
tabIndex++;
}
Height = top + 10 + 55;
}
public object this[string dataPropertyName]
{
get
{
if (Option == null)
{
throw new ArgumentNullException();
}
if (!Option.Dictionary.ContainsKey(dataPropertyName))
{
throw new ArgumentOutOfRangeException();
}
return Option.Dictionary[dataPropertyName].Value;
}
}
public bool IsOK { get; private set; }
[Category("SunnyUI"), Description("确定按钮点击事件")]
@ -94,6 +224,55 @@ namespace Sunny.UI
protected virtual bool CheckData()
{
if (Option != null)
{
foreach (var info in Option.Infos)
{
if (info.EditType == EditType.Text)
{
UITextBox edit = this.GetControl<UITextBox>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
if (info.CheckEmpty && edit.Text.IsNullOrEmpty())
{
ShowWarningTip(edit, info.Text + "不能为空");
edit.Focus();
return false;
}
info.Value = edit.Text;
}
if (info.EditType == EditType.Integer)
{
UITextBox edit = this.GetControl<UITextBox>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
info.Value = edit.IntValue;
}
if (info.EditType == EditType.Double)
{
UITextBox edit = this.GetControl<UITextBox>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
info.Value = edit.DoubleValue;
}
if (info.EditType == EditType.Date)
{
UIDatePicker edit = this.GetControl<UIDatePicker>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
info.Value = edit.Value.Date;
}
if (info.EditType == EditType.DateTime)
{
UIDatetimePicker edit = this.GetControl<UIDatetimePicker>("Edit_" + info.DataPropertyName);
if (edit == null) continue;
info.Value = edit.Value;
}
}
}
return true;
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,164 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2020 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@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.
* 使
******************************************************************************
* : UIEditFormHelper.cs
* :
* : V2.2
* : 2020-12-28
*
* 2020-12-28: V2.2.10
******************************************************************************/
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
namespace Sunny.UI
{
public enum EditType
{
Text,
Integer,
Double,
Date,
DateTime
}
public class EditInfo
{
public string DataPropertyName { get; set; }
public EditType EditType { get; set; }
public string Text { get; set; }
public object Value { get; set; }
public bool CheckEmpty { get; set; }
public bool Enabled { get; set; }
public bool HalfWidth { get; set; }
}
public class UIEditOption
{
public readonly List<EditInfo> Infos = new List<EditInfo>();
public readonly ConcurrentDictionary<string, EditInfo> Dictionary = new ConcurrentDictionary<string, EditInfo>();
public string Text { get; set; } = "编辑";
public bool AutoLabelWidth { get; set; }
public int LabelWidth { get; set; } = 180;
public int ValueWidth { get; set; } = 320;
public void AddText(string dataPropertyName, string text, string value, bool checkEmpty, bool enabled = true)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.Text,
Text = text,
Value = value,
CheckEmpty = checkEmpty,
Enabled = enabled
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
public void AddDouble(string dataPropertyName, string text, double value, bool enabled = true, bool halfWidth = true)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.Double,
Text = text,
Value = value,
Enabled = enabled,
HalfWidth = halfWidth
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
public void AddInteger(string dataPropertyName, string text, int value, bool enabled = true, bool halfWidth = true)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.Integer,
Text = text,
Value = value,
Enabled = enabled,
HalfWidth = halfWidth
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
public void AddDate(string dataPropertyName, string text, DateTime value, bool enabled = true, bool halfWidth = true)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.Date,
Text = text,
Value = value,
Enabled = enabled,
HalfWidth = halfWidth
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
public void AddDateTime(string dataPropertyName, string text, DateTime value, bool enabled = true, bool halfWidth = false)
{
if (Dictionary.ContainsKey(dataPropertyName))
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
EditInfo info = new EditInfo()
{
DataPropertyName = dataPropertyName,
EditType = EditType.DateTime,
Text = text,
Value = value,
Enabled = enabled,
HalfWidth = halfWidth
};
Infos.Add(info);
Dictionary.TryAdd(info.DataPropertyName, info);
}
}
}

View File

@ -166,6 +166,7 @@
<Compile Include="Forms\UIDataGridViewForm.Designer.cs">
<DependentUpon>UIDataGridViewForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\UIEditFormHelper.cs" />
<Compile Include="Forms\UIFormService.cs" />
<Compile Include="Forms\UILoginForm.cs">
<SubType>Form</SubType>
@ -558,6 +559,9 @@
<EmbeddedResource Include="Forms\UIDataGridViewForm.resx">
<DependentUpon>UIDataGridViewForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\UIEditForm.resx">
<DependentUpon>UIEditForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\UINotifier.resx">
<DependentUpon>UINotifier.cs</DependentUpon>
</EmbeddedResource>