Buttons in all versions of vb (well vb3 and up) including vb 7.1 (vs 2003) all have a click event, there isn't a property that you can check to tell if a button's been clicked.how to check if a command button is clicked in vb.net 2003?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static clicked As Boolean
Dim reply As Integer
If clicked = True Then
reply = MessageBox.Show("Click OK to keep clicked status on, Cancel to turn it off.", "This button was clicked", MessageBoxButtons.OKCancel)
End If
clicked = True
If reply = 2 Then clicked = False
End Sub
That would only work if all of the coded needed to check that boolean remained inside the click event (that boolean doesn't have scope outside of that sub) which means there's no point in using the boolean in the first place.You could use a static Boolean variable and turn it on or off. Here's a sample using a message box that the user can control:
VB.NET:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Static clicked As Boolean Dim reply As Integer If clicked = True Then reply = MessageBox.Show("Click OK to keep clicked status on, Cancel to turn it off.", "This button was clicked", MessageBoxButtons.OKCancel) End If clicked = True If reply = 2 Then clicked = False End Sub
Private m_ButtonClickBool As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
m_ButtonClickBool = Not m_ButtonClickBool
End Sub