验证的WinForms文本框(在C#) [英] Validating WinForms TextBox (in C#)

查看:234
本文介绍了验证的WinForms文本框(在C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TextBox_Leave事件中,我需要检查在文本框中输入的数字是否在序列号或not.If它不是为了然后我需要显示的消息为数字是缺少



例如:



在文本框中我输入3,然后单击标签:
我需要显示的信息为
号不按顺序,数字1和2失踪


解决方案

我不知道这是否也适用在C#2.0,这是我的经验,在C#3.0:



为什么使用TextBox_Leave是什么?使用验证事件的验证事件应被用于验证输入是否正确。



联合使用的ErrorProvider(你可以从工具箱将其拖到形式)来设置一个错误信息:它会显示为一个红色的三角形(闪烁)感叹号



这是ErrorProvider还可以阻止任何提交-动作<。 / p>

In TextBox_Leave event i need to check whether numbers entered in textbox is in serial number or not.If it is not in order then i need to display a message as "number" is missing

For example :

In textbox i have entered 3 and click tab : I need to display message as "Number is not in order , number "1" and "2" is missing "

解决方案

I don't know whether this also works in c#2.0, this is my experience in c#3.0:

Why do you use TextBox_Leave for that? The Validating-event should be used for validating whether input is correct.

Combine using the Validating-event with using an ErrorProvider (you can just drag it from the toolbox onto the form) to set an error message: it will be displayed as a (blinking) exclamation mark in a red triangle.

An ErrorProvider can also block any submit-actions.

这篇关于验证的WinForms文本框(在C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆