CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2009
    Posts
    9

    VB 2005 shortcut button

    i need some help in understanding shortcut button code as well as writing them

    i have created a button on a form that refuses to operate . the codes are right
    its enabled, visible. mouse not disable.
    but it just refuses to operate

    so i'm trying out another way.. but programming a shortcut button
    in the program left by my predecessor


    Private Sub frmReport1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
    Select Case e.KeyChar
    Case ChrW(20) 'if staff press 'Ctrl-T' to terminate
    Application.Exit()
    End Select
    End Sub


    is ChrW(20) preset or something? i seriously cant figure it out


    the operation of my shortcut button is that
    when in form2, depressing the shortcut keys will call up form1 and close form2

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 2005 shortcut button

    Here it is: The Paragraph sign!

    Code:
    ? chrw(20)
    although formatting loses it

    that's the same as debug.print chrw(20)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: VB 2005 shortcut button

    Is there any event handler code written for the button event handler? Just look out for buttonname_Clik(...) method in the form.

    From the look of it, it looks like the code is written in the KeyPress event handler of the form.

    To know what chrW(20) means, look at the ASCII table
    http://www.asciitable.com/

    ChrW() method returns the character associated with the decimal. For example ChrW(65) would return "A".

  4. #4
    Join Date
    Sep 2009
    Posts
    9

    Re: VB 2005 shortcut button

    hmmm... to SHUJA ALI there is no Ctrl + T in the ASCII site that u've shown me...
    cant make out much.

    perhaps u could show me how i should write my code let say i wanna press Ctrl + B to do the operation

    By the way i've only been using VB'05 for 3weeks

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 2005 shortcut button

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: VB 2005 shortcut button

    XiaoToose, the VB.NET Forum is located here. This is the VB 6 Forum.

    This seems like a global shortcut / a hook, am I correct ¿

    Have look at MCLHotkey :

    http://www.codeproject.com/KB/vbscript/mclhotkey.aspx

  7. #7
    Join Date
    Sep 2009
    Posts
    9

    Re: VB 2005 shortcut button

    hmmmm...
    this is part of my code
    i wanna add that by pressing Ctrl -Z (ChrW(26)) it will call another form and closes the current form





    If e.KeyChar <> ChrW(13) And e.KeyChar <> "0" Then
    KeyNum = e.KeyChar.ToString
    Select Case KeyNum
    Case ChrW(20) 'if staff press 'Ctrl-T' to terminate
    End
    Case "1" To "9" 'user response to the system according to the Landolt-C direction and system will record down the answer given by user

    Case Else 'if user press other keys, there will have a beep sound, mouse being enabled and cursor will be shown until the user click on the ok button from error message
    Beep()
    mouse.EnableMouse()
    Cursor.Show()
    MessageBox.Show("Error", "Error", MessageBoxButtons.OK)
    'Cursor.Hide()
    'mouse.DisableMouse()
    Timer1.Enabled = True
    Exit Sub
    End Select
    End If



    can anyone guide me?
    do i just stuff the new line of case code in or wad?

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: VB 2005 shortcut button

    [Moved to VB.NET]
    The title of the thread is little confusing. it talks about button but then there doesn't seem to be any button there.

    In order to trap Ctrl + Z keys, you would need to handle KeyDown event rather than KeyPress. A simple example would be
    Code:
        Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If e.Control And e.KeyCode = Keys.Z Then
                MessageBox.Show("You pressed Ctrl + Z")
            End If
        End Sub

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

Featured