下面是StringGrid中的网格创建按钮;
请参考,改动即可符你的杨求!
procedure Tform1.mybuttons; //动态创建按钮;
var
ab:Tbutton;
tc:Tcomponent;
i:integer;
nam:string;
begin
for i:=1 to 9 do
begin
ab:=Tbutton.Create(self);
ab.ParentWindow:=Stringgrid1.Handle;
ab.Top:=(stringgrid1.DefaultRowHeight+stringgrid1.GridLineWidth)*i;
ab.Left:=stringgrid1.ColWidths[1]+stringgrid1.ColWidths[0]-20;
ab.Width:=20;
nam:='ab'+inttostr(i);
ab.Name:=nam;
ab.Caption:=IntToStr(i);
tc:=FindComponent(nam);
(tc as TButton).Visible :=True;
(tc as TButton).OnMouseDown :=myclick; //生成按的分配事件;
end;
end;
procedure Tform1.myclick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); //自定义MouseDown事件
begin
tname:=(Sender as TButton).Name; //开始记录按钮的名字;
sendmessage(handle,my_msg,strtoint((Sender as TButton).caption),0);
end;
请参考,改动即可符你的杨求!
procedure Tform1.mybuttons; //动态创建按钮;
var
ab:Tbutton;
tc:Tcomponent;
i:integer;
nam:string;
begin
for i:=1 to 9 do
begin
ab:=Tbutton.Create(self);
ab.ParentWindow:=Stringgrid1.Handle;
ab.Top:=(stringgrid1.DefaultRowHeight+stringgrid1.GridLineWidth)*i;
ab.Left:=stringgrid1.ColWidths[1]+stringgrid1.ColWidths[0]-20;
ab.Width:=20;
nam:='ab'+inttostr(i);
ab.Name:=nam;
ab.Caption:=IntToStr(i);
tc:=FindComponent(nam);
(tc as TButton).Visible :=True;
(tc as TButton).OnMouseDown :=myclick; //生成按的分配事件;
end;
end;
procedure Tform1.myclick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); //自定义MouseDown事件
begin
tname:=(Sender as TButton).Name; //开始记录按钮的名字;
sendmessage(handle,my_msg,strtoint((Sender as TButton).caption),0);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货