I'm using delphi 2009 and have created a popup menu.
object PopupMenu1: TPopupMenu
object lmm1: TMenuItem
Caption = 'lm/m'#178
end
end
as soon as i have a "²" in a popup menu, it'll appear as "lm/m²(L)". using maManual for AutoHotKeys doesn't help...it still appears the same way. it's like hotkeys because each menu item gets a new one.
"lm/m² (L)"
"m/m² (M)"
"am/m² (N)"
"bm/m² (O)"
must i use "lm/m2" instead of "lm/m²" if i want the (L) to go away?
used internationally, i'd still expect the "²" would be displayed properly.
thank you for your help!
here's the solution i devised after studying/debugging the source of the TMenuItem.InternalRethinkHotkeys and TMenuItem.GetAutoHotkeys:
object PopupMenu1: TPopupMenu
Left = 184
Top = 272
object MenuItem1: TMenuItem
AutoHotkeys = maManual
Caption = 'lm/m'#178
end
end
The AutoHotKeys property applies to keyboard accelerators when the ALT key is held down. What you are seeing is the TMenuItem.ShortCut property at work instead. Make sure it is set to scNone for any item you do not want "(#)" to appear on.
Related
I am creating sidebar images with the help of TRzGroup. I already have created TRzGroup with caption Print Now and added item named Print to it. I am planning to add a small printer icon image at the left hand side of the menu item as shown in figure at bottom. How it can be done ?
object RzGroup2: TRzGroup
Items = <
item
Caption = 'Print'
ImageIndex = 4
OnClick = RzGroup2Items0Click
end>
Opened = True
OpenedHeight = 47
DividerVisible = False
SmallImages = ImageList1
Special = True
Caption = 'Print Now'
ParentColor = False
end
While this code is extracted from somewhere in the code SmallImage attribute is assigned to ImageList1. I assume it is for image menu. I checked at object inspector there is SmallImages property but not sure how to create ImageList1 and assign to SmallImages.
Drop a TImageList from the Delphi component palette (Win32 page) onto your form (or in a data module used by the form). Double-click that new TImageList, click the Add button on the ImageList Editor that appears, and add images. Close the `ImageList Editor'.
Go back to your form. Click on the RzGroup2 item, and drop down the list in the Object Inspector for the SmallImages property, and choose the imagelist you added in the first step.
Set the ImageIndex of the Print item to the appropriate index in the ImageList you assigned to the RzGroup in the previous step.
I need to change the text of a TMenuItem in Delphi 7, when the popup menu is already popped up.
My popup menu has
OwnerDraw := true;
I'd like to use:
popupmenu.repaint();
or
popupmenu.refresh();
but they do not exist. How can I do it?
You can call MenuChanged on the menu item to force it to be updated. This is a protected member to you need to gain access to that member by the well-known protected member hack.
type
THackedMenuItem = class(TMenuItem);
....
THackedMenuItem(MyMenuItem).MenuChanged(True);//forces redraw of owner drawn item
We know that if we set a shortcut (for example, Ctrl + F2) to a TMenuItem, the menu item will be executed automatically once the shortcut specified is pressed, and the shortcut description will be also shown when the menu is displayed.
But is there a way to have the shortcut descriptions visible on the menu items but make the menu don't respond to the shortcuts automatically?
You might ask me why I want this, here is the situation:
In a multiple document (like firefox's multiple tabs) program, there are multiple instances of TPopupMenu thus multiple TMenuItem objects have the same shortcuts, but I only want the menuitems in the active document window respond to the shortcuts.
Edit 1: Sorry, I wanted to simplify my question and I described it wrongly - actually, I use TActionList and link the actions to menu items.
Edit 2: Just found: I think I can use TApplicationEvents.OnShortCut Event to intercept the shortcuts before they are being dispatched to the menus/actions... I'll try and will update my questions when I get a result.
Use the tab (#9) character to indicate the shorcut part of the text in standard menus. You can set the Caption property of the menu item or the action component that the menu item is bound to by either editing the 'dfm' or at run-time to include the tab character:
procedure TForm1.FormCreate(Sender: TObject);
begin
Action1.Caption :=
Action1.Caption + #9 + ShortCutToText(ShortCut(VK_F2, [ssCtrl]));
Unless you also assign to the ShortCut property itself of the menu item or the action, the click/execute event will not be fired.
How to remove the Accelerators from TMainMenuActionBar ?
can't seem to find the AutoHotKey = maManual property to change, nor to find any other property that will cause the right effect.
(Assuming the question is about TActionMainMenuBar) you would set the AutoHotKeys property through the ActionManager component that the action bar is linked to (through its ActionManager property). Unlike the TMainMenu's AutoHotKeys, this one is a boolean property.
To set the property at design time,
Select the 'ActionManager' component on the form
Click the ... button on the right side of the ActionBars property in OI.
Select your MainMenuBar from the popped up Editing ActionManager1.ActionBars' dialog.
Click the ... button on the right side of the Items property in OI, which will launch the Editing ActionManager1.Items dialog
Do not select any of the items at this time. Instead, set the AutoHotKeys property to True or False in OI.
At run time you can do:
ActionManager1.ActionBars[0].Items.AutoHotKeys := False;
Note that you might need to re-set the Caption of an Item after toggling AutoHotKeys. I.e. 'F&ormat' -> 'Format'.
I have a main menu in an MDI parent form, and it as a main menu.
Now I need to change the first level caption of my first menu item in runtime. How can I do that?
--- Update ---
Sorry. I forgot to tell you that the mainMenu is housed in a TcontrolBar.
I think that is the problem because all answer so far don’t work. I had tried all that before.
But this only occurs for the first level, all other levels change correctly.
Perhaps I'm missing something, but it seems to be very simple:
MainMenu1.Items[0].Caption := '&Hello'; // first top-level item
MainMenu1.Items[1].Caption := '&World'; // second top-level item, etc.
In the Menu Editor (at design time in the IDE), click on the menu you want to change, open the property inspector and change the name to something relevant, i.e MyFirstMenu.
Then in your code, whenever you want to change the menu items caption you can use:
MyFirstMenu.Caption := 'A New Caption';
or if the Main Menu is built dynamically see the answer TOndrej gave above.
[Edit1]
Do you mean you can set the caption successfully on the menu item but do not see the change on the TControlBar?
If you are using the old technique of adding a TToolbar inside of a TControlBar, then adding a tool button for each top menu item, then what you see in the form as top level menu items are actually the tool buttons. Set their caption directly, and everything should work.