动态创建button并显示菜单

1楼: 我的form上有3个Panel,我要在指定的Panel上动态创建多个Button,请问各位,这代码如何写?点这个button时要能弹出菜单

2楼: var
btn1:TButton;
begin
btn1:=TButton.create(owner)
btn1.parent:=panel1
.....
end

3楼: var
button1:Tbutton
begin
button1:=Tbutton.create(nil);
button1.parent:=panel1;
end;

4楼: btn1.OnClick:=yourprocedure

5楼: 对了,先谢各位了,我还要实现:点动态创建的这个BUTTON时弹出一个菜单

6楼: button1.popupmenu:=PopupMenu1;如进销存

7楼: 同意楼上.

8楼: procedure TForm1.Button2Click(Sender: TObject);//create buttons
var
i:integer;
const
name='mybutton';
begin
if Edit1.Tag=0 then
begin
for i:=1 to 10 do
begin
Tbutton.Create(self).Name:=name+inttostr(i);
with Tbutton(findcomponent(name+inttostr(i))) do
begin
left:=10;
height:=20;
// width:=3;
top:=i*20+30;
parent:=self;
popupmenu:=PopupMenu1;
end; 字串4
end;
Edit1.Tag:=1;
end;
if edit1.tag=1 then
abort;
end;

9楼: loveqingfeng:
能否按鼠标左键也弹出菜单?(现在右键是可以了)

10楼: popupmenu:=PopupMenu1;
onclick:=PopupMenu1.Popup(self.Button1.Left ,self.Button1.Top );

posted @ 2011-10-25 17:58  byronming  阅读(194)  评论(0编辑  收藏  举报