0

当我单击鼠标右键时,将运行以下过程。该过程运行良好,它在我的按钮周围放置了一个带边框。我想要完成的是当用户再次单击鼠标右键时,权重设置为 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
4

2 回答 2

1

您需要的是一个打开的值。我假设您的右键单击意味着什么,所以只需设置一个变量并将 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
于 2013-07-11T18:17:25.217 回答
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
于 2013-07-12T19:02:48.713 回答