当我在c#中从文本框移动到下一个文本框时,如何执行代码?

当我在c#中从文本框移动到下一个文本框时,如何执行代码?,c#,C#,在我的程序中,我制作了一个文本框,其中一个是FileNo_txt,所以当我移动到另一个文本框时,我想检查数据库中是否存在该文件号 您需要订阅文本框的离开事件。 private void FileNo_txt_Leave(object sender, System.EventArgs e) { //check if that file number is exist in the database or not //PatientName_txt.Focus(); if you

在我的程序中,我制作了一个文本框,其中一个是FileNo_txt,所以当我移动到另一个文本框时,我想检查数据库中是否存在该文件号


您需要订阅文本框的
离开事件。

private void FileNo_txt_Leave(object sender, System.EventArgs e)
{
    //check if that file number is exist in the database or not

    //PatientName_txt.Focus(); if you want to automatically focus any textbox
}
了解更多信息

还要在构造函数(表单构造函数)中添加此行


如果是winforms,您是否检查过“离开”事件?请多读几遍…是winforms还是webforms?谢谢你,它很管用
private void FileNo_txt_Leave(object sender, System.EventArgs e)
{
     //check if that file number is exist in the database or not.

}
this.FileNo_txt.Leave+= new System.EventHandler(this.FileNo_txt_Leave);