Results 1 to 3 of 3

Thread: [RESOLVED] Hi

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Resolved [RESOLVED] Hi

    I have a VB6 form containing 3 command buttons.I want to create a shortcut to each control.For example when they press F1, command1 is executed,when they press F2 command2 is executed, when they press ESC command Exit is executed.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Hi

    Hi is not a proper title.

    Set the keypreview property of your form to true and write this
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     Select Case KeyCode
    3.         Case vbKeyF1
    4.             Call Command1_Click
    5.         Case vbKeyF2
    6.             Call Command2_Click
    7.         Case vbKeyF3
    8.             Call Command3_Click
    9.     End Select
    10. End Sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Hi

    Quote Originally Posted by engnouna
    when they press ESC command Exit is executed.
    You don't need code for this. Place a standard command button on the form and enter 'Cancel' as its Caption property, and put Unload Me in its click event. Next, set the control's Cancel property to True. When Cancel Property is set to True VB executes the button's Click() event whenever you press the [Esc] key (as well as when you click it).

    BTW:
    Quote Originally Posted by Shuja Ali
    Hi is not a proper title.
    This is correct. Something like "Relate Function Keys To Command Buttons" would be more accurate.

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