Results 1 to 4 of 4

Thread: [2005][Resolved] Toolstrip Shorcut Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    [2005][Resolved] Toolstrip Shorcut Question

    Okay, I have a tool strip and it has a shortcut for a button.
    Code:
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            Me.KeyPreview = True
            If e.KeyCode = Keys.Enter Then
                e.SuppressKeyPress = True
                Go1.PerformClick()
            End If
        End Sub
    But when the program first loads I have to press on the main form to make the shortcut be able to be used. How can I get around this?

    Thank you,
    Adam
    Last edited by admeech29; Mar 26th, 2007 at 10:48 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Toolstrip Shorcut Question

    This is not a new topic and should have been added to your previous thread. You should be setting the KeyPreview property of the form to True in the designer. The whole point of setting KeyPreview to True is so that the form will receive all keybourd events. If you wait until a keyboard event is received to set the property to True then you will have already missed some keyboard events. In your previous thread I posted this:
    Set the form's KeyPreview property to True, handle the KeyDown event
    implying that the property is set first, not inside the event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Toolstrip Shorcut Question

    Please ask your questions on the forum, not in personal messages, particularly if you already have a thread dedicated to the topic.

    Open your form in the designer, open the Properties window, set the KeyPreview property to True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: [2005] Toolstrip Shorcut Question

    Thank you very much. It worked perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width