[英]How to get all components (Tlabel,Tedit …) in a form in Delphi?
I successfully coded a runtime event that changes the size of my TLabel
when I re-size the form 我成功编码了一个运行时事件,该事件在重新调整表单大小时会更改
TLabel
的大小
procedure TForm3.pack(Sender: TObject);
begin
Label1.Font.Size:=Floor(50*(Form3.Width/Screen.Width)*(Form3.Height/Screen.Height));
end;
Now I want to get an array of all the components on my form, so I loop on and re-size them. 现在,我想获取表单上所有组件的数组,因此我继续循环并调整它们的大小。
Any help please, if there is a predefined option or procedure thanks to tell me about it (like responsive) 如果有预定义的选项或过程,请告诉我有关帮助(例如响应式)的任何帮助
Thanks 谢谢
You can use the form's Controls
property. 您可以使用表单的
Controls
属性。 Since all controls inherit from TControl
, and TControl
has a Font
property, it makes it pretty easy (although the property is protected in TControl
, so you'll need an interposer class): 由于所有控件都继承自
TControl
,并且TControl
具有Font
属性,因此它非常简单(尽管该属性在TControl
受保护,所以您将需要一个插入器类):
type
TCtrl = class(TControl);
var
i: Integer;
NewSize: Integer;
begin
NewSize := Floor(50*(Form3.Width/Screen.Width)*(Form3.Height/Screen.Height));
for i := 0 to ControlCount - 1 do
TCtrl(Controls[i]).Font.Size := NewSize;
end;
Note that some controls (such as TPanel
and TTabSheet
) can parent other controls, so they'll have their own Controls
list. 请注意,某些控件(例如
TPanel
和TTabSheet
)可以成为其他控件的父级,因此它们将具有自己的“ Controls
列表。 You'll need to loop through those as well. 您还需要遍历这些内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.