如何在窗口应用程序中使用验证

编程入门 行业动态 更新时间:2024-10-25 10:28:22
本文介绍了如何在窗口应用程序中使用验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作基于窗口的应用程序.我在一个表单中有一个标签客户名称.我想在用户不输入名称时使用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 } }

更多推荐

如何在窗口应用程序中使用验证

本文发布于:2023-10-14 22:39:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   窗口   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!