True); TCustomLabel(Fcomponent).Refresh; SetAutoSizePropert
在网上查了许多资料去阐述如安在dephi中去实现组件随窗口巨细的变革而变革,然都不尽如人意。有人说用组件的align + anchors 这两个属性去控制,,但是我用了之后,让我大惊掉色。把anchors属性下面的四个值都变为true.如果用户用鼠标去拖动窗口,那么窗口上的组件像是中了夺命书生的面目全非脚一样,根基上就没有所谓的五官之态。
下面就介绍我的要领,同样本人的要领也是看了网友们的资料才得以完成的。
(1) 下载TFormResizer组件
我用的是第三方插件TFormResizer,首先下载一个Easysize.rar,(百度一下,应该不难找到) 解压之后,其文件中内容如下:
本人建议应该把Easysite源文件,还有Easysize.d32, Easysize.dcu这三个文件放到你的dephi安置目录中的lib目录下,因为这里面根基上都是dephi的组件。这个组件默认的是标签不随窗口巨细的转变而转变,其他的组件随窗口巨细的转变而转变。如果想选择默认的方法,那么就不要改削这个源文件,直接进行安置这个组件即可。(在这里注意:不管你以前是否设置Label标签的AutoSize属性,他城市酿成true)。
2.改削Easysize源文件
(1).在TSingleResizer的结构要领里,即在 constructor TSingleResizer.Create(LinkedControl, ParentForm : TControl;IncFont : Boolean;MinFS, MaxFS : Integer)要领里注释失最后几句:
{ But do not adjust width of labels (to avoid
interaction of label auto-sizing with re-sizing) }
if FComponent is TCustomLabel then
FFlexWidth := false;
把上面的这几句话注释失
(2).在procedure TSingleResizer.Resize(OwnerHeight, OwnerWidth; HeightRatio, WidthRatio : Double)要领里在最后几行里找到:
{ If component is a label, save original AutoSize value,
and set value temporarily to False }
if FComponent is TCustomLabel then
begin
OldAutoSize := GetAutoSizeProperty(FComponent);
SetAutoSizeProperty(FComponent, False);
end;
{ end W.K. insert }
和
{ begin W.K. insert }
{ If component is a label, set AutoSize temporarily to
True, call Refresh, and finally restore original value. }
if FComponent is TCustomLabel then
begin
SetAutoSizeProperty(Fcomponent, True);
TCustomLabel(Fcomponent).Refresh;
SetAutoSizeProperty(FComponent, OldAutoSize);
end;
{ end W.K. insert }
把上面的话用大括号注释失。
(3)至此,源文件改削完毕
3.安置FormResizer这个组:
打开dephi软件,本人用的是dephi7, 点击 component ->Install Component ,呈现如下界面:
在Unit file name 那一行上点击 Browse按钮 加载你适才你解压的Easysize源文件,完成之后点击OK按钮,弹出如下界面:
点击Comile按钮,这样就在Tag标签页上呈现www 上呈现了FormResizer组件。
4.在form窗口中加如下代码:
(1) procedure TForm2.FormCreate(Sender: TObject);
begin
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/34987.html