加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi组件,用于在运行时显示/隐藏控件

发布时间:2020-12-15 09:27:46 所属栏目:大数据 来源:网络整理
导读:在Delphi中我在运行时显示/隐藏控件,并且它看起来不太好,因为控件突然出现或消失,所以任何人都知道一个组件可以执行show / hide(使用visible属性)但是有某种动画? 谢谢 解决方法 用 AnimateWindow来试试吧.只有WinControls,它看起来并不令人惊叹: procedur
在Delphi中我在运行时显示/隐藏控件,并且它看起来不太好,因为控件突然出现或消失,所以任何人都知道一个组件可以执行show / hide(使用visible属性)但是有某种动画?

谢谢

解决方法

用 AnimateWindow来试试吧.只有WinControls,它看起来并不令人惊叹:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Button2.Visible then
    AnimateWindow(Button2.Handle,250,AW_HIDE or AW_VER_NEGATIVE or AW_SLIDE)
  else
    AnimateWindow(Button2.Handle,AW_VER_POSITIVE or AW_SLIDE);
  Button2.Visible := not Button2.Visible; // synch with VCL
end;

编辑:隐藏的线程版本同时显示多个控件:

type
  TForm1 = class(TForm)
    ..
  private
    procedure AnimateControls(Show: Boolean; Controls: array of TWinControl);
    procedure OnAnimateEnd(Sender: TObject);
  public
  end;

implementation
  ..

type
  TAnimateThr = class(TThread)
  protected
    procedure Execute; override;
  public
    FHWnd: HWND;
    FShow: Boolean;
    constructor Create(Handle: HWND; Show: Boolean);
  end;

{ TAnimateThr }

constructor TAnimateThr.Create(Handle: HWND; Show: Boolean);
begin
  FHWnd := Handle;
  FShow := Show;
  FreeOnTerminate := True;
  inherited Create(True);
end;

procedure TAnimateThr.Execute;
begin
  if FShow then 
    AnimateWindow(FHWnd,AW_VER_POSITIVE or AW_SLIDE)
  else 
    AnimateWindow(FHWnd,AW_HIDE or AW_VER_NEGATIVE or AW_SLIDE);
end;

{ Form1 }

procedure TForm1.OnAnimateEnd(Sender: TObject);
begin
  FindControl(TAnimateThr(Sender).FHWnd).Visible := TAnimateThr(Sender).FShow;
end;

procedure TForm1.AnimateControls(Show: Boolean; Controls: array of TWinControl);
var
  i: Integer;
begin
  for i := Low(Controls) to High(Controls) do
    with TAnimateThr.Create(Controls[i].Handle,Show) do begin
      OnTerminate := OnAnimateEnd;
      Resume;
    end;
end;


procedure TForm1.Button5Click(Sender: TObject);
begin
  AnimateControls(not Button1.Visible,[Button1,Button2,Button3,Edit1,CheckBox1]);
end;
?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读