Solved

Keyboard Shortcuts, Windows, Alt Key

Posted on 2016-08-11
4
49 Views
Last Modified: 2016-08-15
I have an Windows app for which I want the keyboard shortcuts to be shown.  By this I mean the underscore.  I understand that the user has to hit the alt key to show them, and that this was a Windows behavior change at some point.   How can I show them by default just within my app?
0
Comment
Question by:HLRosenberger
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41752478
This is done system-wide using the accessibility options in the Control Panel. If you wish to override this default behavior you'll probably need to subclass the Button control and override the OnPaint event. This means you need to handle painting the rectangle as well as the text. To fully implement this properly you'll need to deal with painting during hover and click actions as well. It's not impossible but it's a bit of a task.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 41752538
that's too much work.  I thought maybe there was an easy way.  What about send the ALT key to my app?
0
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41752583
OK, interesting idea. Yes, you should be able to do this. I experimented with it a little. You can't actually do it on the Form_Load event handler since the form hasn't fully rendered yet. The quick and dirty way to do it is to add a Timer control to the form, set its properties as follows:
(Name): [whatever you want]
Enabled: True
GenerateMember: True
Interval: 1
Modifiers: Private
Tag:
Then add a Tick event handler and put this code in there:
        private void timer1_Tick(object sender, EventArgs e)
        {
            SendKeys.SendWait("%{UP}");
            timer1.Enabled = false;
        }

Open in new window

Voila! You've sent an ALT+UP keystroke to your form. I'm still looking into how to send just an ALT key by itself but that doesn't seem to be an option. ALT+UP is somewhat innocuous and shouldn't cause any adverse side-effects unless your form is specifically looking for that keystroke.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41756241
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question