检查Button是否单击 [英] check if Button Clicked

查看:128
本文介绍了检查Button是否单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个文本框,其中有一个事件可以触发查询



我想知道如何检查按钮是否单击以便当我单击按钮时,文本框事件将不会触发查询



我尝试过使用MouseHover事件按钮和布尔值,但文本框事件仍然执行



对不起,如果我没有添加我的代码







在我的文本框离开事件

Hi
I have a Textbox with an event of Leave that fires query

I want to know how to check if a button is click so that when I ever I click the button the textbox event won't fire the Query

I've tried using a MouseHover event for the button and a boolean but the textbox event still execute

sorry if I didn't add my code



On my Textbox Leave event

Dim chkBtnStatus As Boolean

Private Sub TxtboxLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtBox.Leave
If chkBtnStatus Then
    Dim MainMenu As New MainForm
    Me.Close
    MainMenu.Show
    Exit Sub
End If
RunQuery()
End Sub





其中



Where

Public Sub RunQuery()

Select familyName From Contacts Where FirstName = '" & Textbox.Text & "'
//Lets jump to the result skipping the command and datareader codes
FamilyNameLbl.Text = DataRead(0).ToString

End Sub





在我的Button.Click事件中



Inside my Button.Click Event

chkBtnState = True





以上代码完美无缺

我的客人我的计划将无法工作

离开事件将始终激活



The above codes works perfectly fine
I guest my Plan won't work
Leave event will always fire

推荐答案

文本框事件将始终在按钮单击事件之前触发。没有办法绕过它,因为文本框在按钮获得之前失去焦点,它只是事物的顺序。



也许使用文本框的离开事件并不是你想要做的最好的方法,因为你没有告诉我们你的期望是什么ed函数是(为什么使用Leave on textbox),也没有向我们展示任何代码,它几乎不可能帮助你解决你想要做的事情。
The textbox event will always fire before the button click event. There is no way around this, since the textbox loses focus before the button gains it, its just the order of things.

Maybe using the leave event for the textbox isn't the best way to do what you are trying to do, since you didn't tell us what your desired function is (why use the Leave on textbox), nor did you show us any code, its really almost impossible to help you with a solution around what you want to do.


你做Boolean类型的类变量。在按钮的单击事件中,您将此变量设置为true。或者你可以在第一次点击按钮后禁用该按钮。



You make a class variable of type Boolean. In the button's click event you set this variable to true. Or you could disable the button after it has been clicked the first time.

Public Class form1
  Private hasBeenClicked As Boolean
  Private Sub btn_Clicked(...) Handles btn.Click
    If Not hasBeenClicked Then
       'do query
    End If
    hasBeenClicked = True
  End Sub
...
End Class


这篇关于检查Button是否单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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