Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you underscore file menu shortcuts? 1

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB

How do you show up the underscore beneath the letter key that activates a file menu item?
I notice in my app (and in Delphi interestingly), I only see the underscore once I have pressed ALT, whereas in the likes of Word, Firefox and many others, they are there permanently.

I've used the ampersand in the caption to set the ALT+key to activate them.


Steve (Delphi 2007 & XP)
 
I think the reason they created that functionality is that windows will determine a unique letter at runtime for you to press in the event that your menus are dynamic.

In my D2006 the menu has a property called AutoHotkeys which governs the assignment. It doesn't talk about the persistence.
 
You mean the underscore that appears on most typical applications in a persistent way? For a caption of an actionable control (menu item, button, checkbox, radiobox, etc), all you need to do is type a & before the letter you want, and it will make it into a hotkey for the app.

For example, most apps tend to have a "File menu" option. To hotkey the F, you enter the menu item caption as "&File", and then the F will be underscored. When the app runs, pressing ALT+F will activate that particular option.

----------
Measurement is not management.
 

Yes I mean that underscore, and I have the ampersand set, like you say, for example, &File, and press ALT and F and it activates the File menu.
However, what I mean is, for example, while I'm typing this in Firefox up on the Filefox menu, the F of File is showing an underscore, as is the E of Edit etc, without me pressing ALT.

But in my app, while it is running none of the menu items are showing the underscore.
If I press ALT, then sure enough, File is highlighted and all the underscores appear.

What I'd like is the underscores to show without pressing ALT, so you can see what the keypress should be before pressing ALT.

Steve (Delphi 2007 & XP)
 
However, what I mean is, for example, while I'm typing this in Firefox up on the Filefox menu, the F of File is showing an underscore, as is the E of Edit etc, without me pressing ALT.

I really have no idea. The underscores are always persistent for me, both within Delphi (TD2006) and within any apps that I create. That seems to be default since I know I haven't touched any setting to change that.

Speaking of which, is there some setting within the IDE that you might have changed?

----------
Measurement is not management.
 

I've not changed any settings in Delphi, certainly not knowingly anyway!

Looking at more apps on this PC, I note that Word also has the persistent underscores, but Windows and Internet Explorer don't, nor does Notepad++ or Notepad.

I'm thinking it might be a windows setting, and that Firefox and Word have them permanently programmed in?


Steve (Delphi 2007 & XP)
 
Okay I found out:

I'm thinking it might be a windows setting, and that Firefox and Word have them permanently programmed in?

This is indeed correct to a point. This is an XP eye candy setting, which is consistent for the menus on anything programmed with the XP style menu systems.

Right click on the Desktop, then click properties. Select the appearance tab, and click the Effects button. Uncheck the last option: "Hide underlined letters...until I
press the Alt key" and you should get something consistent with what you are looking for.

----------
Measurement is not management.
 

Cool, yes that's exactly the effect I want, thanks.

But...I'm wondering if I can force that effect, like Firefox and Word does, without the user needing to make the setting?

Is it for example possible to Set the menu captions to include one character of underlined text, which would simulate the effect?



Steve (Delphi 2007 & XP)
 
Hi Steve you can force this behaviour:

point the OnAdvancedDrawItem method of each menu item to this method:

Code:
procedure TFrm_main.AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
begin
 if odnoAccel in State then
  State := State - [odnoAccel];
 TMenuItem(Sender).OnAdvancedDrawItem := nil;
 DrawMenuItem(TMenuItem(Sender), ACanvas, ARect, State);
 TMenuItem(Sender).OnAdvancedDrawItem :=  AdvancedDrawItem;
end;


Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I've pasted the proc into my app:
Code:
procedure TMainForm.AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
begin
 if odnoAccel in State then      // this proc to force underscore on menu items
  State := State - [odnoAccel];
 TMenuItem(Sender).OnAdvancedDrawItem := nil;
 DrawMenuItem(TMenuItem(Sender), ACanvas, ARect, State);
 TMenuItem(Sender).OnAdvancedDrawItem :=  AdvancedDrawItem;
end;

And set all my menu items as in the pic, but no joy?


Steve (Delphi 2007 & XP)
 
 http://www.tenchy.co.uk/temp/menuitem.gif
forgot to say:

you must set the Ownerdraw property of the main menu to True.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 

Cool, that's great many thanks again!


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top