实在看不懂上面这位说的什么意思~!我给出一例: var index: Integer; NewItem: TMenuItem; begin for index := 0 to 3 do begin NewItem := TMenuItem.Create(PopupMenu1); // create the new item PopupMenu1.Items.Add(NewItem);// add it to the Popupmenu NewItem.Caption := 'Menu Item ' + IntToStr(index); NewItem.Tag := index; NewItem.OnClick = PopupMenuItemsClick;// assign it an event handler end;具体popupmenuitemsclick事件中的处理无非是记录你要的快捷方式~!
procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin for I := 0 to 4 do begin ComboBox1.Items.Add(IntToStr(I + 1)); end; end;procedure TForm1.Button2Click(Sender: TObject); var I: Integer; miTemp: TMenuItem; begin if ComboBox1.Items.Count <= 0 then Exit; for I := 0 to ComboBox1.Items.Count - 1 do begin miTemp := TMenuItem.Create(Self); miTemp.Caption := ComboBox1.Items[I]; bbb1.Add(miTemp); end; end;
var
index: Integer;
NewItem: TMenuItem;
begin
for index := 0 to 3 do
begin
NewItem := TMenuItem.Create(PopupMenu1); // create the new item
PopupMenu1.Items.Add(NewItem);// add it to the Popupmenu
NewItem.Caption := 'Menu Item ' + IntToStr(index);
NewItem.Tag := index;
NewItem.OnClick = PopupMenuItemsClick;// assign it an event handler
end;具体popupmenuitemsclick事件中的处理无非是记录你要的快捷方式~!
但我想大家没有明白我的意思:
太阳风:你作出来的是delphi的那个reopen按钮的效果!
扬清:你做出来的是动态的popmenu效果!
我希望的是动态生成submenu效果!
是不是我的想法有错误?
var
I: Integer;
begin
for I := 0 to 4 do
begin
ComboBox1.Items.Add(IntToStr(I + 1));
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
I: Integer;
miTemp: TMenuItem;
begin
if ComboBox1.Items.Count <= 0 then
Exit;
for I := 0 to ComboBox1.Items.Count - 1 do
begin
miTemp := TMenuItem.Create(Self);
miTemp.Caption := ComboBox1.Items[I];
bbb1.Add(miTemp);
end;
end;
aaa1
bbb1
ccc1
ddd1
都不包含子菜单项。点击Botton1再点击Botton2后,会增加子菜单
不好意思,一开始没有仔细看你的要求,所以我的第一个回复不符合你的要求