110,547
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 检查文本框是否为空
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static List<TextBox> CheckTextBoxEmpty(params TextBox[] list)
{
List<TextBox> nullList = new List<TextBox>(4);
foreach (TextBox txt in list)
{
if (string.IsNullOrEmpty(txt.Text.Trim()))
{
nullList.Add(txt);
}
}
return nullList;
}
List<TextBox> list = Common.PublicMethod.CheckTextBoxEmpty(txtCode,txtMyName);
if (list.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (TextBox txt in list)
{
sb.Append(txt.Tag + ",");
}
MessageBox.Show(Convert.ToString(sb) + "不能为空");
list[0].Focus();
return;
}
List<string> lst = new List<string>();
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is TextBox)
{
TextBox txt = control as TextBox;
if (string.IsNullOrEmpty(txt.Text))
{
lst.Add(txt.Name);
}
}
}
string str = string.Empty;
for (int i = 0; i < lst.Count; i++)
{
str += lst[i]+" ";
}
MessageBox.Show(str+"为空!");