Solved

Keyboard Shortcuts, Windows, Alt Key

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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