用右键单击事件通过鼠标右键单击事件调用取消过程

时间:2013-07-11 18:12:07

标签: vb.net

当我单击鼠标右键时,会运行以下步骤。程序运行正常,它在我的按钮周围放置一个边框。我想要完成的是当用户再次单击鼠标右键时,权重设置为0,边框设置为无。

这是我的程序:

    Private Sub btnEmployeeDashboard_MouseDown(ByValsender As Object, ByVal myButton As System.Windows.Forms.MouseEventArgs) Handles btnEmployeeDashboard.MouseDown

    If myButton.Button = MouseButtons.Right Then

        btnEmployeeDashboard.Border.ColorIndex = 2
        btnEmployeeDashboard.Border.Weight = 4

    End If

End Sub

2 个答案:

答案 0 :(得分:1)

您需要的是要切换的值。我假设您的右键单击意味着什么,所以只需设置一个变量并将if和if语句添加到您的事件中。

Dim ButtonClicked as boolean = false 

Private Sub btnEmployeeDashboard_MouseDown(ByValsender As Object, ByVal myButton As System.Windows.Forms.MouseEventArgs) Handles btnEmployeeDashboard.MouseDown

If myButton.Button = MouseButtons.Right Then

    If ButtonClicked then 

         btnEmployeeDashboard.Border.Weight = 0
         ButtonClicked = false
    else

         btnEmployeeDashboard.Border.ColorIndex = 2
         btnEmployeeDashboard.Border.Weight = 4
         ButtonClicked = true
    endif



End If

End Sub

答案 1 :(得分:0)

以下是修改后的代码。我使用切换设置为静态。所以作为一个布尔值,它给了我正在寻找的东西。

    Private Sub btnEmployeeDashboard_MouseDown(ByValsender As Object, ByVal myButton As System.Windows.Forms.MouseEventArgs) Handles btnEmployeeDashboard.MouseDown

    Static Toggle As Boolean

    If myButton.Button = MouseButtons.Right Then

        If Toggle Then

            btnEmployeeDashboard.Border.Weight = 1

        Else

            btnEmployeeDashboard.Border.ColorIndex = 2
            btnEmployeeDashboard.Border.Weight = 4

        End If

    End If
    Toggle = Not Toggle

End Sub