如果在单击Button2之前的任何时间点击Button1,则提示消息

时间:2017-05-23 18:11:11

标签: vb.net

如果用户点击了button1然后稍后点击了button2,我需要提示一条消息。

代码看起来像:

Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click

   if button1.clicked then 

      messagebox.show("Are you sure you want to click button2 after clicking button1?" , "Warning", MessageBoxButtons.OKCancel)

         if messagebox.userselected.ok then   

             Me.Dispose()
             Me.Close()

         else
             'do nothing
         end if

   end if

End Sub

1 个答案:

答案 0 :(得分:3)

Dim Flag as Boolean = False

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click  
   Flag = True       
End Sub

Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click   
  If Flag Then
    If MessageBox.Show("Are you sure you want to click button2 after clicking button1?" , "Warning", MessageBoxButtons.OKCancel) = DialogResult.Ok Then
      Me.Close()
    End If
  End If
End Sub