Do you feel that the menu provided by Delphi is really unattractive to use? You can use Delphi's own VCL control to implement an IE-style menu! Features include: floating buttons, drag positioning, graphics... all of which do not require any third-party controls or a lot of programming!
Implementing an IE-style menu requires the following steps:
1. Define an ordinary menu in the normal way;
2. Hide the defined menu from the window;
3. Add CoolBar and ToolBar to the window as the menu bar;
4. Map the menu to the ToolBar button;
5. Program for special effects (optional).
The first step is to define a normal menu in the normal way.
Add a TMainMenu control to the window, and then define menu items, icons, shortcut keys, etc. in the usual way.
The second step is to hide the defined menu from the window.
The defined menu will be automatically displayed on the window. This is because when a TMainMenu control is added to the window, the Menu property of the TForm object is automatically set to the added TMainMenu object. In order to use our own defined menu, this menu must be hidden. Clear TForm.Menu and the defined menu will not be automatically displayed.
The third step is to add CoolBar and ToolBar to the window as the menu bar.
Add a TCoolBar control to the window, and then place a TToolBar control inside it. Set the AutoSize property of TCoolBar and TToolBar to True, set the Flat property of TToolBar to True, and set the ShowCaptions property of TToolBar to True. In this way, a blank menu bar appears above the window. Next we will add menu items to this menu bar.
The fourth step is to map the menu to the ToolBar button.
Right-click TToolBar and select New Button from the pop-up menu to add the first button to the menu bar. Set the AutoSize property and Grouped property of this button to True, and then change the Caption property to the text of the menu item. For example, the Caption property might be set to &File. Finally, set the MenuItem property of this button to the corresponding menu item defined in TMainMenu. For example, the MenuItem property might be set to mnuFile. After these settings, the button is linked to the menu item, and the corresponding menu will pop up when the button is clicked.
The fifth step is to program for special effects (optional).
After the previous four steps, the new menu can already work normally. However, if you want to implement other special effects, such as the dragging and positioning of CoolBar, you need to do some more programming work. These contents are no longer the subject of this article and will not be discussed. Interested readers can refer to Delphi's help.
Readers are welcome to provide their own opinions on this article.