Windows窗体中的事件 [英] events in windows form

查看:68
本文介绍了Windows窗体中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为密码字段创建两个文本框.一个用于密码,第二个用于重新输入密码.
我已经在文本更改事件中编写了代码.那
textbox1.text!= textbox2.text
但是每次我更改文本时都会检查一次.我想要仅执行代码的事件.用户写完完整的密码后. Textchange事件可以执行此操作,但是会在每个字符之后执行.我要在密码完全键入后执行代码.

I am making two textbox for password field. One for password and second for re enter password.
I have written code in text change event. That
textbox1.text != textbox2.text
but it checks when everytime i change text. I want event which will only execute the code. After user have written the full password. Textchange event does it but it executes after every single character. I want to execute the code afte password have been totally typed.

推荐答案

使用其他TextBox的Validating事件,此处,仅在用户完成操作后执行代码输入密码.
Use the Validating event of other TextBox, here, the code is only executed when the user has finished entering the password.


您可以使用其他方法,但不能使用textChange来检查两个密码
例如,您可以在method下创建并在button_click中调用它;
you can use another method but no textChange for check two password
for example you can make under method and in button_click call it;
 public  void CheckTwoPassword(string textbox1,string  textbox2)
{
 if(textbox1==textbox2)
  {
    //do some work 
  }
}



然后您的按钮点击



and your button click

public void Button_Click(sender s,object o)
{
 CheckTwoPassword(textbox1.text,textbox2.text);
}



您可以在第二个文本框的"Leave"或"LostFocus"事件中比较密码
Hi,
You can compare passwords in "Leave" or "LostFocus" event of the second textbox


这篇关于Windows窗体中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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