Results 1 to 5 of 5

Thread: Keyboard shortcuts VB.NET

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    30

    Keyboard shortcuts VB.NET

    I m creating a VB.NET application and i want to create a keyboard shortcut to insert a dat but i want the shortcut to be ctrl-;

    Now i have a hidden button with caption &; ... but this is Alt-; .

    so how can i do this with ctrl instead of Alt?

    tnx in advance

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Keyboard shortcuts VB.NET

    I would set the form's key preview to true and then use the key down event of the form to run the code. The example below is a hidden button on a form although it doesn't really need to have the keyboard shortcut thingy set because this code will always respond to the user pressing Ctrl + C. If the button is hidden, I'm not sure why you would care about the shortcut, but that's beside the point....give it a whirl and let me know how you get on!

    VB Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.         If e.Control = True Then
    3.             Select Case e.KeyCode
    4.                 Case Keys.C
    5.                     Button1_Click(Button1, New EventArgs)
    6.             End Select
    7.         End If
    8.     End Sub
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         MessageBox.Show("Hello World")
    12.     End Sub
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    30

    Re: Keyboard shortcuts VB.NET

    this doesn't seem to work when the focus is on a textbox for example.
    But i used the code on the keydown event of the textbox i wanted to insert the date in.

    tnx a lot

  4. #4
    New Member
    Join Date
    May 2005
    Posts
    5

    Re: Keyboard shortcuts VB.NET

    I have an addressbook that also has the add button to add additional records. Instead of pressing the tab key while entering information in every textbox, how can I use the keydownpress for each textbox if a user enters information so it can scroll to the next textbox?
    Also having a login page instead of using the tab keypress, I would like to use the enter keypress to login after entering the username and password. How can I use in code for the keypress.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    30

    Re: Keyboard shortcuts VB.NET

    you can do it like this with the keypress event.

    Private Sub txtPass_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPass.KeyPress
    If Asc(e.KeyChar) = 13 Then
    '''here comes the code you want to execute
    End If
    End Sub

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