unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
MyMenu1,MyMenu2: TMainMenu;
Item: TMenuItem;
procedure TForm1.FormCreate(Sender: TObject);
begin
{建立第一个菜单}
MyMenu1 := TMainMenu.Create(Self);
MyMenu1.AutoHotkeys := maManual;
Item := TMenuItem.Create(MyMenu1);
Item.Caption := 'AA';
MyMenu1.Items.Add(Item);
Item := TMenuItem.Create(MyMenu1);
Item.Caption := 'BB';
MyMenu1.Items.Add(Item);
Item := TMenuItem.Create(MyMenu1);
Item.Caption := 'CC';
MyMenu1.Items.Add(Item);
{建立第二个菜单}
MyMenu2 := TMainMenu.Create(Self);
MyMenu2.AutoHotkeys := maManual;
Item := TMenuItem.Create(MyMenu2);
Item.Caption := 'XX';
MyMenu2.Items.Add(Item);
Item := TMenuItem.Create(MyMenu2);
Item.Caption := 'YY';
MyMenu2.Items.Add(Item);
Item := TMenuItem.Create(MyMenu2);
Item.Caption := 'ZZ';
MyMenu2.Items.Add(Item);
Self.Menu := nil; {当前 Form 没有指向任何一个菜单}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.Menu := MyMenu1; {指向第一个菜单}
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.Menu := MyMenu2; {指向第二个菜单}
end;
end.
效果图:
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步