Solved

Keyboard Shortcuts, Windows, Alt Key

Posted on 2016-08-11
4
51 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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