* UIEditForm:增加一个方法

This commit is contained in:
Sunny 2021-02-21 22:29:09 +08:00
parent 5b5fa59e28
commit 8c6d72f1a0
7 changed files with 51 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,6 +20,7 @@
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
@ -49,9 +50,10 @@ namespace Sunny.UI
if (option == null || option.Infos.Count == 0) return;
base.Text = option.Text;
int tabIndex = 0;
int top = 55;
List<Control> ctrls = new List<Control>();
if (option.AutoLabelWidth)
{
float size = 0;
@ -86,8 +88,21 @@ namespace Sunny.UI
edit.Top = top;
edit.Text = info.Value.ToString();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
if (info.EditType == EditType.Password)
{
UITextBox edit = new UITextBox();
edit.Left = option.LabelWidth;
edit.Width = option.ValueWidth;
edit.Top = top;
edit.Text = info.Value.ToString();
edit.Parent = this;
edit.PasswordChar = '*';
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
if (info.EditType == EditType.Integer)
@ -99,8 +114,8 @@ namespace Sunny.UI
edit.Top = top;
edit.IntValue = info.Value.ToString().ToInt();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
if (info.EditType == EditType.Double)
@ -112,8 +127,8 @@ namespace Sunny.UI
edit.Top = top;
edit.DoubleValue = info.Value.ToString().ToDouble();
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
if (info.EditType == EditType.Date)
@ -124,8 +139,8 @@ namespace Sunny.UI
edit.Top = top;
edit.Value = (DateTime)info.Value;
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
if (info.EditType == EditType.DateTime)
@ -136,15 +151,22 @@ namespace Sunny.UI
edit.Top = top;
edit.Value = (DateTime)info.Value;
edit.Parent = this;
edit.TabIndex = tabIndex;
edit.Name = "Edit_" + info.DataPropertyName;
ctrls.Add(edit);
}
top += 29 + 10;
tabIndex++;
}
pnlBtm.BringToFront();
Height = top + 10 + 55;
int tabIndex = 0;
foreach (var ctrl in ctrls)
{
ctrl.TabIndex = tabIndex;
tabIndex++;
}
}
public object this[string dataPropertyName]
@ -228,7 +250,7 @@ namespace Sunny.UI
{
foreach (var info in Option.Infos)
{
if (info.EditType == EditType.Text)
if (info.EditType == EditType.Text || info.EditType == EditType.Password)
{
UITextBox edit = this.GetControl<UITextBox>("Edit_" + info.DataPropertyName);
if (edit == null) continue;

View File

@ -32,7 +32,8 @@ namespace Sunny.UI
Integer,
Double,
Date,
DateTime
DateTime,
Password
}
public class EditInfo
@ -85,6 +86,25 @@ namespace Sunny.UI
Dictionary.TryAdd(info.DataPropertyName, info);
}
public void AddPassword(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.Password,
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))