Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 VB 6.0 - Command Buttons And KeyDown
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
D_homes




PostPosted: Sun Oct 23, 2011 1:06 pm   Post subject: VB 6.0 - Command Buttons And KeyDown

I'm having an issue with the KeyDown function that is caused by having a command button on the form.
The button is automatically highlighted during run time (if there was more than one button then using the arrow keys would switch between them), this prevents any use of the KeyDown function for me.

I've tried messing around with the 'TabIndex' and 'TabStop' properties of the command button, but nothing has worked.

i.e
code:

Public Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyUp Then 'If the user presses the Up arrow
        'Do Stuff
    ElseIf KeyCode = vbKeyDown Then
        'Do Stuff
    End If
End Sub
Sponsor
Sponsor
Sponsor
sponsor
Numbah51




PostPosted: Wed Nov 30, 2011 2:57 pm   Post subject: Re: VB 6.0 - Command Buttons And KeyDown

Hi,

As far as I'm aware, the form itself can never have focus as long as there are controls on it which can have focus. For what you're looking to do, you can set the Form's KeyPreview property to true which will allow the form to recieve keyboard event before those other controls. However, say you have a command button and it has focus by default, then you will not be able to get the key state of the enter button (as the enter button will press the command button). Hope this helped.

-Mike
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: