1.
//隐藏与显示菜单
Self.Menu :=nil; {隐藏菜单}
Self.Menu := MainMenu1; {显示菜单}
2.
右键 Create submenu 添加下级菜单
3.
菜单历史信息
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm1 = class(TForm)
MainMenu1:TMainMenu;
OpenDialog1:TOpenDialog;
mniFile:TMenuItem;
mniOpen:TMenuItem;
N1:TMenuItem;
mniExit:TMenuItem;
proceduremniOpenClick(Sender: TObject);
procedurealert(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.alert(Sender: TObject);
begin
if Sender is TMenuItem then
ShowMessage(TMenuItem(Sender).Caption);
end;
procedure TForm1.mniOpenClick(Sender: TObject);
var
mni: TMenuItem;
event: TNotifyEvent;
begin
if not OpenDialog1.Execute then Exit;
mni := TMenuItem.Create(Self);
mni.Caption := OpenDialog1.FileName;
event := alert;
mni.OnClick := event;
MainMenu1.Items.Items[0].Insert(2, mni);
if MainMenu1.Items.Items[0].Count = 4then
begin
mni :=TMenuItem.Create(Self);
mni.Caption:= '-';
MainMenu1.Items.Items[0].Insert(3,mni);
end;
end;
end.