相当于代码中的设计师指南 [英] Equivalent to designer guidelines in code
问题描述
VCL表单设计师为各自文本基线的对齐控件提供了粉色指南:
但据我所知,这对于标签和复选框不起作用。 更新:它适用于标签,如果您将控件准确地放在,例如按 Ctrl - 箭头。现在,在某些表单上,我创建了代码中的控件,例如
ed:= TEdit.Create(Self);
ed.SetBounds(...);
ed.Parent:= SomePanel;
等。我如何确保他们的文本基线对齐?我想要这样编辑,组合框,标签和复选框。结果应该是这样的(没有红线,当然:-)):
编辑:我目前的方法是调用类似 AlignTop(8,[Edit1,ComboBox1] [CheckBox1,Label1]);
with
procedure ControlArray_SetTop(const AControls:array of TControl; ATop : 整数);
var
i:整数;
begin
for i:= Low(AControls)to High(AControls)do
AControls [i] .Top:= ATop;
结束
程序AlignTop(ATop:Integer; const AControls:TControl数组; const ALabelLikeControls:数组的TControl);
begin
ControlArray_SetTop(AControls,ATop);
ControlArray_SetTop(ALabelLikeControls,ATop + 3);
结束
我的目标是用更强大,更少麻烦的东西来替换它。
该指南在设计时代码中执行,许可证禁止您随应用程序一起运送,因此您只能使用它从中学习,然后自行重新实现。查找
DesignIntf.TBaseComponentGuidelines
DesignEditors.TComponentGuidelines
VCLEditors.TControlGuidelines
类(在{RADStudio\version} \source\ToolsAPI目录中)。也许这归结为一些简单的东西,如
Label1.Top:=(Edit1.Top + Edit1.Height) - Label1.Height + GetMagicConstant;
其中 GetMagicConstant
类似于 TControlGuidelines.GetTextBaseline()
。
The VCL form designer offers pink guidelines for aligning controls at their respective text base lines:
But as far as I can tell this doesn't work for labels and checkboxes. Update: It works for labels if you place the controls exactly, e.g. by Ctrl-arrow. It kind of works for checkboxes - see screenshot.
Now, on some forms I'm creating controls in code, e.g.
ed := TEdit.Create(Self);
ed.SetBounds(...);
ed.Parent := SomePanel;
etc. How can I ensure that their text base lines are aligned? I'd like to have this for edits, comboboxes, labels and checkboxes. The result should look like this (without the red line, of course :-)):
Edit: My current approach is to call something like AlignTop(8, [Edit1, ComboBox1], [CheckBox1, Label1]);
with
procedure ControlArray_SetTop(const AControls: array of TControl; ATop: Integer);
var
i: Integer;
begin
for i := Low(AControls) to High(AControls) do
AControls[i].Top := ATop;
end;
procedure AlignTop(ATop: Integer; const AControls: array of TControl; const ALabelLikeControls: array of TControl);
begin
ControlArray_SetTop(AControls, ATop);
ControlArray_SetTop(ALabelLikeControls, ATop + 3);
end;
My goal is to replace it with something more robust and less hacky.
The guidelines are implemented in designtime code which license prohibits you to ship with your app so you can only use it to learn from it and then reimplement it yourself. Look up
DesignIntf.TBaseComponentGuidelines
DesignEditors.TComponentGuidelines
VCLEditors.TControlGuidelines
classes (in "{RADStudio\version}\source\ToolsAPI directory"). Perhaps it comes down to something simple as
Label1.Top := (Edit1.Top + Edit1.Height) - Label1.Height + GetMagicConstant;
where GetMagicConstant
is similar to TControlGuidelines.GetTextBaseline()
.
这篇关于相当于代码中的设计师指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!