• delphi实现窗体组建随窗体大小改变而改变


    在网上查了许多资料去论述如何在dephi中去实现组件随窗口大小的变化而变化,然都不尽如人意。有人说用组件的align + anchors 这两个属性去控制,但是我用了之后,让我大惊失色。把anchors属性下面的四个值都变为true.如果用户用鼠标去拖动窗口,那么窗口上的组件像是中了夺命书生的面目全非脚一样,基本上就没有所谓的五官之态。

    下面就介绍我的方法,同样本人的方法也是看了网友们的资料才得以完成的。

    (1) 下载TFormResizer组件

    我用的是第三方插件TFormResizer,首先下载一个Easysize.rar,(百度一下,应该不难找到) 解压之后,其文件中内容如下:

    Dephi如何实现组件随窗口大小的改变而改变 - i_love_you_chai - i_love_you_chai的博客

    本人建议应该把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 ,出现如下界面:

    Dephi如何实现组件随窗口大小的改变而改变 - i_love_you_chai - i_love_you_chai的博客
    在Unit file name 那一行上点击 Browse按钮   加载你刚才你解压的Easysize源文件,完成之后点击OK按钮,弹出如下界面:
    Dephi如何实现组件随窗口大小的改变而改变 - i_love_you_chai - i_love_you_chai的博客
    点击Comile按钮,这样就在Tag标签页上出现www 上出现了FormResizer组件。
    4.在form窗口中加如下代码:
          (1) procedure TForm2.FormCreate(Sender: TObject);
                    begin
                                formresizer1.ResizeFonts := true;   //设置字体是否随窗口大小的改变而改变。
                                 FormResizer1.InitializeForm;
                    end;
          (2)在form的OnResize事件上增加如下代码:
                   procedure TForm2.FormResize(Sender: TObject);
                   begin
                         FormResizer1.ResizeAll;    
                   end;
           
    自此,窗口中的组件就可以随窗口大小的改变而改变了。
     
    http://blog.163.com/i_love_you_chai/blog/static/1708911082010112105057644/
  • 相关阅读:
    Cookie中文乱码问题
    [转]Resolving kernel symbols
    [转]Blocking Code Injection on iOS and OS X
    [转]About the security content of iOS 8
    [转]iOS: About diagnostic capabilities
    [转]iOS hacking resource collection
    [转]Patching the Mach-o Format the Simple and Easy Way
    [转]Use the IDA and LLDB explore WebCore C + + class inheritance
    [转]Avoiding GDB Signal Noise.
    [转]http://www.russbishop.net/xcode-exception-breakpoints
  • 原文地址:https://www.cnblogs.com/semth/p/8390691.html
Copyright © 2020-2023  润新知