Hi..
i have a little homework from my school
my lecture want me to create a little program in VB.NET

he wanted if i pressed Ctrl + S in ...it will appears msgbox....
and one more...if i click button...it like i press Ctrl + S


Can u help me....
thx for attention

Since you want use 2 keys for the shortcut you could do following thing...

Private ctrlPressed As Boolean = False

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("procedure goes here")
    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.Control And Not ctrlPressed Then
            ctrlPressed = True
            Return
        ElseIf e.KeyCode = Keys.S And ctrlPressed Then
            Button1_Click(Me, New System.EventArgs)
        End If
        ctrlPressed = False
    End Sub

if you want to use just one Key you can do this via the "text" property. if you set the button text to My&Button then "b" will be the shortcut.
hope it helps

if you want to use just one Key you can do this via the "text" property. if you set the button text to My&Button then "b" will be the shortcut.
hope it helps

To piggy back what he said, you must also have UseMnemonic on the button set to true when you go the route listed above. It's defaulted to True though, so unless you inadvertently changed it, it should work fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.