如何获取我自己创建的控件的名字呀。 如何获取我自己创建的控件的名字呀。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 名字在你创建的时候就定了啊。显示出来的是caption属性。 btn1 := TButton.Create(self);// btn1就是这个动态创建的控件的name unit MainUnit;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IniFiles, ExtCtrls, StdCtrls, Buttons;type TForm1 = class(TForm) Image1: TImage; BitBtn1: TBitBtn; procedure FormCreate(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure BOnclick(Sender:TObject); end;var Form1: TForm1; IniFile:TIniFile; buttonPosition:Array[1..50] of record top:integer; left:integer; end; button:Array[1..20] of TBitbtn; buttonname:Tbitbtn;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);var count,i:integer; buttons:string; bitmap:Tbitmap;begin bitmap:=Tbitmap.Create; bitmap.LoadFromFile(ExtractFilePath(application.ExeName)+'mail.bmp'); IniFile:=TIniFile.Create(ExtractFilePath(application.ExeName)+'position.ini'); count:=20; for i:=1 to 20 do begin buttons:='button'+inttostr(i); buttonposition[i].top:=IniFile.ReadInteger(buttons,'top',-1); buttonposition[i].left:=IniFile.ReadInteger(buttons,'left',-1); button[i]:=tBitbtn.Create(self); button[i].Top :=buttonposition[i].top; button[i].Left:=buttonposition[i].left; button[i].Caption :='话筒'+inttostr(i); button[i].Layout :=blGlyphtop; button[i].Glyph :=bitmap; button[i].Height :=60; button[i].Name :='button'+inttostr(i); button[i].OnClick :=BOnclick; button[i].Parent :=form1; end;end;procedure TForm1.BOnclick(Sender:TObject);beginend;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin buttonname.Top :=y; buttonname.Left :=x;end;procedure TForm1.BitBtn1Click(Sender: TObject);begin buttonname :=self.BitBtn1;end;end.我想要点击一个任意一个我所创建的按钮后,在窗体上点右键,使它就移到当前位置。如何实现呀。 楼主想做什么 ?结楼上朋友的:btn1 := TButton.Create(self);// btn1就是这个动态创建的控件的name获取: s := Btn1.Name ;楼主想做什么 ? “点击一个控件,然后在窗口任意位置点击右键,将该控件移到相因位置 “ 应该用消息吧, 这样以来要获得最近的 TBitBtn 的句柄,获得句柄简单,而怎样知道是最近点击的要写鼠标钩子 。 是这样还是我还没有搞清楚楼主的问题 ???? 呵呵,wjlsmail(计算机质子)哥哥你肯定是想复杂了,我是这么理解的在这个函数里加东西就行了啊procedure TForm1.BOnclick(Sender:TObject);begin buttonname := TButton(Sender); end; :) 的确楼上大哥这个楼主现在已经好了,楼主那个贴子中 laihecongxi(兴哥) 给了非常简单高效的方法 :)http://expert.csdn.net/Expert/topic/1277/1277561.xml?temp=3.324527E-02 偶认为你应该建个链表保存它,用的时候再取出来就成了如果控件类型不清楚可以判断一下类型嘛还有,控件的tag和hint属性都可以记录一个标识(偶也是刚学得) 钩子(Hook)函数的回调函数的调用 列移动的问题 执行vbs文件, WinExec('hygl.vbs',SW_SHOW),怎么不能用? 分辨率问题 dbgrid delphi如何封装WinHttp.WinHttpRequest的事件 如何制作安装程序的软件?100分相酬!!!! 一个比较白痴的问题 关于打印预览的问题 CreatePolygonRgn Delphi 还是 BCB? 怎么实现指针的移动?类似于C语言当中的p++(P为指针)
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, ExtCtrls, StdCtrls, Buttons;type
TForm1 = class(TForm)
Image1: TImage;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure BOnclick(Sender:TObject);
end;var
Form1: TForm1;
IniFile:TIniFile;
buttonPosition:Array[1..50] of record
top:integer;
left:integer;
end;
button:Array[1..20] of TBitbtn;
buttonname:Tbitbtn;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
count,i:integer;
buttons:string;
bitmap:Tbitmap;
begin
bitmap:=Tbitmap.Create;
bitmap.LoadFromFile(ExtractFilePath(application.ExeName)+'mail.bmp');
IniFile:=TIniFile.Create(ExtractFilePath(application.ExeName)+'position.ini');
count:=20;
for i:=1 to 20 do
begin
buttons:='button'+inttostr(i);
buttonposition[i].top:=IniFile.ReadInteger(buttons,'top',-1);
buttonposition[i].left:=IniFile.ReadInteger(buttons,'left',-1);
button[i]:=tBitbtn.Create(self);
button[i].Top :=buttonposition[i].top;
button[i].Left:=buttonposition[i].left;
button[i].Caption :='话筒'+inttostr(i);
button[i].Layout :=blGlyphtop;
button[i].Glyph :=bitmap;
button[i].Height :=60;
button[i].Name :='button'+inttostr(i);
button[i].OnClick :=BOnclick;
button[i].Parent :=form1;
end;
end;procedure TForm1.BOnclick(Sender:TObject);
begin
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
buttonname.Top :=y;
buttonname.Left :=x;
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
buttonname :=self.BitBtn1;
end;end.我想要点击一个任意一个我所创建的按钮后,在窗体上点右键,使它就移到当前位置。如何实现呀。
结楼上朋友的:
btn1 := TButton.Create(self);// btn1就是这个动态创建的控件的name获取: s := Btn1.Name ;楼主想做什么 ?
在这个函数里加东西就行了啊procedure TForm1.BOnclick(Sender:TObject);
begin
buttonname := TButton(Sender);
end;
如果控件类型不清楚可以判断一下类型嘛
还有,控件的tag和hint属性都可以记录一个标识(偶也是刚学得)