Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I right align the shortcut keys in Menu?

I add my menu items shortcut keys, but they are poorly arranged.

enter image description here

and I need to make it like this:

enter image description here

like image 445
Mediator Avatar asked Feb 11 '11 23:02

Mediator


People also ask

What is the shortcut key for align right?

What is the right align shortcut key? The alignment keyboard shortcut keys can vary depending on what program is used and the type of computer. However, generally speaking, use Ctrl + L to left align, Ctrl + E to center, Ctrl + R to right align, and Ctrl + J to justify text.

How do I align shortcuts?

The shortcut key Ctrl + E is used to align the line or selected text to the centre of the screen.


2 Answers

Ah, I think I finally figured out how to do this (it had been puzzling me for quite some time how you'd gotten the two different screenshots...). It turns out there are two ways that you can instruct Windows to align shortcut keys in a drop-down menu.

The first (and probably most standard) way is to insert a tab character (\t) in the string corresponding to the menu text. This produces the bottom example shown in your original question, the one where all the identifiers are left-aligned and some overhang slightly. This is the standard in almost all Microsoft applications, and the only option that I knew existed until a few minutes ago.

     The first option, created using a tab character delimiter, with shortcut key sequences left-aligned     Sample resource string: &Print…\tCtrl+P

The second way is to replace that \t escape sequence with \a in the resource string (which, yes, strangely enough would normally indicate an alert bell). This causes Windows to right align all of the shortcut key sequences in the menu, producing the example illustrated in your first screenshot. This does produce a menu that uses screen space more efficiently (it's smaller), but this comes at the cost of a neat alignment of each of the shortcut key sequences down their left-hand margins, which I think makes for slightly easier readability.

     The second option, created using an '\a' delimiter, with shortcut key sequences right-aligned     Sample resource string: &Print…\aCtrl+P

So if you want your menus to look like the second example in your original question (Yes, I've confusingly arranged my samples backwards. Sorry), you need to delimit the shortcut key sequence with a tab character (\t) in the resource file containing your menu item text strings.

The strange thing is that you claim to be using .NET WinForms, which handles all of this automatically (saving you from the pain of messing with resource files). I know for a fact that it inserts tab characters, and all of the menus I've ever seen it generate do look like your second example.

The best thing to do is switch your menu to the old MainMenu control included with earlier version of the .NET Framework. (To do this, you'll probably have to right-click on the Toolbox and add the control manually—it isn't there by default on later versions of Visual Studio.) This will ensure that you see the alignment behavior you expect, consistent with all of the standard Windows applications like Notepad. It also produces menus that look like the native operating system menus (in Vista and 7, they are painted blue) rather than the amateur-looking owner-drawn menus produced by the MenuStrip control that are completely out-of-place in modern versions of Windows.

Microsoft's official documentation does confirm that the MainMenu control is still supported for future use, so there's no reason to fear using it in your apps. I highly recommend everyone use this instead:

Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.

like image 190
Cody Gray Avatar answered Sep 19 '22 17:09

Cody Gray


They are 'right' aligned, as you can see. (No pun intended).

Right

This is default behaviour for a menu. You'll need custom drawing to do it differently.

like image 20
GolezTrol Avatar answered Sep 22 '22 17:09

GolezTrol