Results 1 to 4 of 4

Thread: Shortcut Keys in Visual Basic

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    78

    Shortcut Keys in Visual Basic

    Hi, I was wondering about how to apply shortcut keys (like control+c and control+v) in visual basic

    There was a thread on this I found but I tried all the codes and variations but nothing worked, like nothing would happen when I pressed the keys

    could someone give me the code about how to activate a "control+t" and a "control+r" control? thanks

    the farthest I got was:

    private sub form3_key down...........handles form3.keydown
    if e.keycodes = keys.control and e.keycodes = keys.t then
    msgbox("hi")
    end if
    end sub

    I that was the best looking code I got, but it didn't work
    i also did
    For Each item As Control In Me.Controls
    AddHandler item.KeyDown, AddressOf Form3_KeyDown
    Next

    i noticed if I did code for just pressing the control key it worked but when I tried to use two keys it didnt'

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Shortcut Keys in Visual Basic

    Did you set the KeyPreview property of the form to true?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    307

    Re: Shortcut Keys in Visual Basic

    e.keydata should give you the codes you're looking for. Try this and see the different results:

    Code:
     Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            lblCode.Text = e.KeyCode
            lblData.Text = e.KeyData
            lblValue.Text = e.KeyValue
        End Sub
    e.keydata should reflect the ctrl+key combination.
    Last edited by dkahn; Dec 23rd, 2009 at 09:52 PM.

  4. #4
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Shortcut Keys in Visual Basic

    You can use Andalso for that :

    Code:
    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
            If e.Control = True AndAlso e.KeyCode = Keys.D0 Then
                MsgBox("manhit")
            End If
        End Sub
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

Tags for this Thread

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