×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Button press using key stroke

Button press using key stroke

Button press using key stroke

(OP)
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?

RE: Button press using key stroke

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

RE: Button press using key stroke

(OP)
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.

RE: Button press using key stroke

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!

RE: Button press using key stroke

Sorry I pressed too quickly!

Obviously you then change the Picture property on the appropriate KeyPress event to simulate the Click Event

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources