怎样取得当前控件的Name(20分)

G

gyang

Unregistered / Unconfirmed
GUEST, unregistred user!
1。如在Form1上面有一个Edit1和Llabel1两个控件:
当Edit1获得焦点的时候,在Label1中显示Edit1的Name;
2。如在Form1上面有多个Edit控件和1个ListBox1控件:
  当Edit3获得焦点的时候(显示ListBox1),单击ListBox1时,返回ListBox的当前
  行的值给Edit3.Text(不用变量怎样做?)
 
1.OnMouseDown事件
Label1.Caption := TControl(Sender).Name;
或者用TTimer来获得:Label1.Caption := ActiveControl.Name;
2.
procedure TForm1.Edit3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit3.Text := ListBox1.Name;
end;
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit3.Text := ListBox1.Items[ListBox1.ItemIndex]
end;
 
利用Sender参数
TControl(Sender).Name;
 
接受答案了.
 

Similar threads

顶部