本文介绍了显示必填字段reg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
如何在C#Windows窗体中显示必填字段?有人可以建议我吗?

谢谢和问候,
A.Harisankar.

Dear All,
How to show Mandatory fields in C# windows form? Can any one suggest me?

Thanks and Regards,
A.Harisankar.

推荐答案

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (textBox1.Text == "")
    {
        errorProvider1.SetError(textBox1, "This is a mandatory field");
        e.Cancel = true;
    }
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
    errorProvider1.Clear();
}



通过将e.Cancel设置为true,可以防止表单关闭.
通过使用errorProvider1对象的SetError方法,您将在错误的字段旁显示一个小的错误警告.

您可以根据需要添加尽可能多的错误提供程序.

这非常容易使用并且非常有效.

Valery.



By setting e.Cancel to true you prevent the form from closing.
By using the SetError method of the errorProvider1 object, you will make a little error warning flash next to the field in error.

You can add as many errorproviders as necessary.

This is very simple to use and very effective.

Valery.




这篇关于显示必填字段reg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:53