请问大家,如何在winform中对textbox控件进行非空验证呢?只要验证是否非空就可哈。不用其他的验证。
解决方案 »
- xna做个2D功能,Draw可以给定原点等参数绘图,如果想让他二次变化,应该如何操作。
- 关于编码的转换上的一些问题
- 关于arraylist中sort()的用法
- URL 重写分页
- 求BBS(ASP.NET+SQL2000)C#2.0版代码
- 在Web页面中,在<script language="javascript">里面如何访问.net的控件啊?
- 未将对象引用设置到对象的实例
- 这个类定义是什么意思,请帮忙看看
- 关于控件验证RegularExpressionValidator
- 请问为何vb.net有的那个with语句为什么C#中没有。
- c#中出现名为“应为get或set访问器”的错误是什么意思?
- 求一WPF TextBox Style
{
MessageBox.Show("textbox不能为空!");
}
{
//代码
}字符的最好这样写,用“==”不太好
if(textbox1.text.equals("")||textbox2.text.equals("")||......)
{
if (((TextBox)sender).Text.Trim().Equals(""))
MessageBox.Show("不能为空"); }
然后把所有需要验证的TextBox控件的Leave事件,知道这个处理方法上来。
{
MessageBox.Show("不能为空");
}
楼主好像应该看书吧.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;namespace nxCommonClass
{
public partial class NxTextBox : TextBox
{
public NxTextBox()
{
InitializeComponent();
this.Leave += new EventHandler(NxTextBox_Leave); } void NxTextBox_Leave(object sender, EventArgs e)
{
float result;
if(string.IsNullOrEmpty(this.Text))
{
MessageBox.Show("Should be not null!","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
//校验是否是数字
if(!float.TryParse(this.Text, out result))
{
MessageBox.Show("error input!","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
this.Focus();
}
}
}
if (textbox.Text.Trim() == "")
{
MessageBox.Show("textbox不能为空!");
}
以上两个都是可以直接解决的;
这个事件似乎不是很好,一定要鼠标移入textbox事件才能触发