如何在窗口应用程序中使用验证 [英] how to use validation in window application

查看:75
本文介绍了如何在窗口应用程序中使用验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作基于窗口的应用程序.我在一个表单中有一个标签客户名称.我想在用户不输入名称时使用validateatin.我该怎么做

I am making window based application .I am having one label customer name in a form.I want to use validatin whenever user do not enter name.how can I do this

推荐答案

在表单提交事件中,检查名称文本框是否为空或其中是否包含一些数据.如果不是,请发出一条消息,指出它是必需的.停止执行.您尝试过吗?
On form submit event, check if the name textbox is empty or have some data in it. If not, raise a message that it is needed. Stop the execution. Did you try?


这取决于您需要进行多少验证以及何时需要进行验证.
您可以验证用户何时按下按钮-例如输入信息.
或者,您可以验证用户何时离开TextBox.

为此,只需在Button.Click事件中进行检查即可.
要稍后进行处理,请处理TextBox.Leave事件.

就个人而言,我会选择Button.Click路线:它允许用户以他选择的顺序填写内容.


您可以使用代码进一步解释它吗"
It depends on how much validation you need to do and when you need to do it.
You can validate when the user presses a button - to enter the information for example.
Or, you can validate when the user moves away from the TextBox.

To do the former, just do your checks in the Button.Click event.
To do the later, handle the TextBox.Leave event.

Personally, I would go for the Button.Click route: It allows the user to fill things in, in whatever order he chooses.


"can u explain it more using code"
private void myEnterButton_Click(object sender, EventArgs e)
    {
    if (!string.IsNullOrEmpty(myTextBox.Text) && myTextBox.Text != "Bad customer")
        {
        ... All ok.
        }
    else
        {
        ... bad Validation
        }
    }


这篇关于如何在窗口应用程序中使用验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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