Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button press using key stroke

Status
Not open for further replies.

SteveHuck

Electrical
Jan 9, 2003
27
0
0
I'm scratching out some code in VB6 and was wondering if anybody ever tried this?

Can or has anyone been able to make a command button LOOK like it has been clicked when a key on the keyboard has been pressed?

Say a command button on a calculator with the caption "1" appears to depress when the number 1 on the keyboard is pressed?

Is this possible or have i wasted half of a sunday afternoon?
 
Replies continue below

Recommended for you

Activate Keypreview in your form
Then at myForm_KeyPress
check for the keys and activate the button according to the key
It will work also clicking the buttons
 
Hello ielivaz

I have already done what you suggest and everything works fine. What i was wondering was, is there an easy way to make the button APPEAR to depress when the KEYBOARD is stroked. The rest of the code works fine, i was just trying to raise the visual coolness. If it's a big deal dont worry about it.
 
Dead easy!

Draw a bitmap (using MSPaint for instance) the same size as the button will be. It's size in MSPaint will be in pixels, your button size by default is in Twips, so get your Form TwipsPerPixel figure (usually 15 for SVGA displays) and divide button size by TwipsPerPixel to get size in MSPaint.

Do 2 .bmps, one for buttonup and one for buttondown.

On the form set the Command button Style property to 1 - Graphical, and assign the .bmps to the Picture property and the DownPicture property

That's it!
 
Sorry I pressed too quickly!

Obviously you then change the Picture property on the appropriate KeyPress event to simulate the Click Event
 
Status
Not open for further replies.
Back
Top