我想动态的改变窗体的大小,比如说单击某按钮使得form的width增加,但是由于窗体的重画,闪烁得很厉害。请问如何处理才能得到不闪烁的效果。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      Normal: boolean;implementation{$R *.dfm}
    //请看下面两个相互呼应的函数。都可以解决你的问题。你喜欢那个就那个呗。
    //  DisableAlign  EnableAlign
    //LockWindowUpdate(handle);  LockWindowUpdate(0);
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      DisableAlign;
      //LockWindowUpdate(handle);  
      if Normal then
      begin
        Self.Width := Self.Width div 2;
        Self.Height := Self.Height div 2;
      end
      else begin
        Self.Width := Self.Width * 2;
        Self.Height := Self.Height * 2;
      end;
      //LockWindowUpdate(0);
      EnableAlign;
      Normal := not Normal;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Normal := true;
    end;end.