After the main menu is placed in the BCB, the method of custom shortcut keys is implemented.

zhaozj2021-02-16  48

If the brothers who have done the main menu in the toolbar "will find a question: That is, the system will automatically give menu options to add hot keys (if your menu option is English, then it will be under the first letter Converse line, if your menu option is Chinese, then add a shortcut key that is similar (Y), (z) after the menu option is added, and the shortcuts you define your own failure! (Note: I later discovered that if you add similar (H) shortcuts, there will be no such problem. Only when we add similar Ctrl A, F1, Ctrl Alt D, etc. There will be a problem when shortcut; additionally, when setting the images property for TmainMenu, that is, the problem of the menu item is added, the problem of the English menu will still exist. The problem of this is, I also Unclear). Even if we set mainmenu's autohotKeys = Mamanual can't be solved. After I met this problem, I had to ask for experts. Later, with the help of BCB_FANS and JSP, they solved the problem. Therefore, this article is actually the two boss of branches.

First, let's remove the hotkey of the system automatically.

When we put the menu in the toolbar, we see the menu when the program is running is actually the TMAINMENU we design, but a TPopupUpMenu, which is temporary new, and the autohotkeys attribute of this temporary menu is MAAUTOMATIC. , So it will automatically add hot keys to the menu. This problem is found by BCB_FANS (I can't be so powerful, huh, huh), his original words are like this:

"When the menu is displayed, Ttoolbar is not using the original menu that has been designed, but re-establishes a temporary TPopupMenu, adds the menu item of the original menu to this rpopupmenu, and finally shows this temporary TPopupMenu. AutoHotKeys of this TPopUpMenu is Maautomatic, and there is no way to control this temporary TPopupMenu properties. So the displayed menus will automatically add fast-name characters. "

Then BCB_FANs have made a TMenubar themselves, specifically used to make a menu in the toolbar (I am using it now). His implementation method in tmenubar is to replace the system new TPopupmenu with its own TPopUpMenu, set your own TPopupMenu's autohotKeys = MAMANUAL:

"Since there is no way to control the temporary TPopUpMenu, naturally think of using his TPopupMenu to replace the temporary TPopUpMenu, OK, this good office, just set the TtoolButton's DropDownMenu, instead of setting the MenuItem property. And then set This tpopupmenu's autohotKeys is Mamanual, so there is no shortcut. "

Of course, not everyone is like me, I can get the BCB_FANS boss tmenubar, huh, huh. So I asked this question yesterday, I asked this question in the "Impossible Solved Question" post. As a result, the JSP boss will solve the problem I think "impossible solving"!

JSP boss's implementation methods and actual and BCB_FANS are the same, but also the temporary menu of the system with their own TPopUpMenu. Just the BCB_FANS boss's TMenubar encapsulates TToolbar and automatically generates ToolButton and menu items, instead of us to set it manually; and JSP code is just written by completing the automatically generated shortcut, other work has to do it. .

JSP boss code is as follows (note is my own): __ fastcall tform1 :: tForm1 (tComponent * Owner): TFORM (Owner) {tMenuItem * Item; TMENUIIIIIIIIIIIIIIIIIIIIIIIIIIITEM * ITEM1; TPopupmenu

For (int N = 0; n ButtonCount; n ) {ttoolbutton * btn = Toolbar1-> Buttons [n]; if (btn-> DropDownMenu! = null) btn-> menuitem = null; // Remove the system Generated shortcut menu Else if (btn-> menuitem! = Null) {item = btn-> menuitem; menu = new tpopupmenu (this); menu-> autohotkeys = mamanual; // does not automatically generate hot bond btn-> DropDownMenu = Menu; // Add your own new menu if (item-> getparentMenu ()) // set the setting with TMAINMENU {Menu-> bidimode = item-> getparentMenu () -> bidimode; menu-> Images = item-> getParentMenu () -> images;} menu-> helpContext = item-> helpContext; menu-> trackbutton = tbleftbutton; for (int i = item-> count-1; i> = 0; I - ) // Add menu options to your new TPopupmenu {item1 = item-> items [i]; item-> delete (i); menu-> items-> insert (0, item1);}} }

With this code with JSP boss, you can remove those nasty shortcuts (actually replacing the menu, of course, the shortcuts are not). But now the problem is still solving half, that is, only the automatic shortcut, and our own shortcut has not played! What I want to say is that this time is not a shortcut that we set up, similar (n) This shortcut to the horizontal line in this parentheed arc is still easy to use. Only shortcuts that are similar to Ctrl A, Ctrl Alt Z and F1 do not work. Why is this this? I can't find the reason.

Then let's find a way to make your shortcuts! I have achieved this feature by using TactionList, in fact, I also borrowed the previous post and then improved.

We know that TACTIONList can define many Actions (Method: Double-click the TAATIONList control while designing the Settings dialog, you can define Actions yourself), and each Action can use shortcuts to trigger their Onexecute events. Speaking here, I think everyone should understand how to do it. If we set the shortcuts of an Actions and a menu option to the same, for example, set the menu item "Redo" and an Actions shortcut to Ctrl R. Then then trigger the "Redo" menu item on the Actions's Onexecute event (that is, add the code in the Actions on an onexecute event: redOMenu-> Click (); // redOMenu is the name of the "REDO" menu option), then When we press CTRL R, it will trigger "Redo" onclick event, which looks, we set the shortcut (Ctrl R) set by the menu! In this way, we can remove the hot keys generated by the system, and you can define all kinds of suitable shortcuts!

转载请注明原文地址:https://www.9cbs.com/read-24719.html

New Post(0)