通过下面的函数生成了一组Button控件:var ButtonCount:Integer;
var tb:Array [0..100] of TButton;function TForm1.CreateButton(strCaption:String;x,y:Integer):TButton;
var temp:TButton;
begin
temp:=Tbutton.Create (ScrollBox1);
temp.Parent := ScrollBox1;
temp.Caption := strCaption;
temp.Font.Color := clWhite;
temp.Left := x;
temp.Top := y;
end;procedure TForm1.ScrollBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ButtonCount=99 then begin
showmessage ('无法创建新的节点!');
exit;
end;
if Button=mbLeft then begin
tb[ButtonCount]:=CreateButton('按钮'+IntToStr(ButtonCount),x,y);
Inc(ButtonCount);
end;
end;现在要求在每个动态生成的Button控件中响应各自的MouseDown MouseUp MouseMove事件,该如何做呢?
var tb:Array [0..100] of TButton;function TForm1.CreateButton(strCaption:String;x,y:Integer):TButton;
var temp:TButton;
begin
temp:=Tbutton.Create (ScrollBox1);
temp.Parent := ScrollBox1;
temp.Caption := strCaption;
temp.Font.Color := clWhite;
temp.Left := x;
temp.Top := y;
end;procedure TForm1.ScrollBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ButtonCount=99 then begin
showmessage ('无法创建新的节点!');
exit;
end;
if Button=mbLeft then begin
tb[ButtonCount]:=CreateButton('按钮'+IntToStr(ButtonCount),x,y);
Inc(ButtonCount);
end;
end;现在要求在每个动态生成的Button控件中响应各自的MouseDown MouseUp MouseMove事件,该如何做呢?
解决方案 »
- delphi模仿google的suggest出现的问题,如何将光标一直定位在文本框中?
- delphi中如何实现拼音首字母查询(使用sql语句)
- delphi程序在英文系统下如何正常显示中文
- 如何截取窗口后面的屏幕图像?
- 图像格式转换,在线等,急需
- 请教关于trackbar的问题?
- 关于QuickReport打印的问题。(送分了)
- 请太阳风兄和有缘兄回去看看刚才( 我想用一个循环来动态的生成某类的多个对象,加到连表中怎么操作,好象我用了new不能用啊!)的贴子,
- ★★★已知一段弧的两个端点坐标和弧度,如何求出弧的中点坐标★★★
- 请问如何分别将一个word文档和一个excel存入到sql server 数据库的一个表的一个字段中?
- 屏幕的问题,大家帮一把啦!
- 构造函数的一个问题
Btn:TButton;
begin
Btn:=TButton.create(self);
Btn.onmousedown:=BtnMouseDown;
end;
procedure TForm1.BtnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
end;
temp.OnMouseDown:=BMouseDown;
temp.OnMouseUp:=BMouseUp;
temp.OnMouseMove:=BMouseMove;其中BMouseDown,BMouseUp,BMouseMove为自定义的事件函数。
procedure BtnMouseDown/MouseUp/MouseMove(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
需在Type中声明!