按键在.NET中按BasicButton

时间:2017-05-22 21:29:26

标签: .net vb.net

我正在尝试按下我使用按键构建的按钮。

  • 如果我使用鼠标并单击按钮,完全没问题,一切正常。
  • 我试过用&在文本框中提供短按,同时按下ALT。没有快乐

我对.NET知之甚少,但是关于一天的表情,我可以说它不是那么直接。

我想添加一个快捷方式,例如按B键就像我按下按钮一样,在这种情况下:BasicButton1_Click

以下是我目前的所有代码。

Public Class MainForm

    Private Sub MainForm_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
        If e.Alt AndAlso e.KeyCode = Keys.W Then
            BasicButton1.PerformClick()
        End If
    End Sub
    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
    End Sub

    '**************************************
    '* Filling the form with a gradient
    '**************************************
    'Private Sub MainForm_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    'Dim rect As New System.Drawing.Rectangle(0, 0, e.ClipRectangle.Width, e.ClipRectangle.Height)
    'Dim gradientBrush As New Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Height), System.Drawing.Color.FromArgb(180, 100, 200), System.Drawing.Color.FromArgb(110, 200, 255))
    'e.Graphics.FillRectangle(gradientBrush, rect)
    'End Sub

    Private Sub BasicButton1_Click(sender As Object, e As EventArgs) Handles BasicButton1.Click

    End Sub

    Private Sub BasicButton7_Click(sender As Object, e As EventArgs) Handles BasicButton7.Click

    End Sub

    Private Sub BasicButton2_Click(sender As Object, e As EventArgs) Handles BasicButton2.Click

    End Sub

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub BasicButton5_Click(sender As Object, e As EventArgs) Handles BasicButton5.Click

    End Sub

    Private Sub BasicButton3_Click(sender As Object, e As EventArgs) Handles BasicButton3.Click

    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

在要作为关键触发器的角色之前,在Button.Text中放置一个&

例如,如果按钮文本是“Click Me!”,并且您希望 Alt-M 触发按钮,则将Button.Text设置为Click &Me!

就是这样。 Windows / .NET将负责其余的工作。