判断窗体存在

来源:互联网 发布:西西里的美丽传说知乎 编辑:程序博客网 时间:2024/05/18 06:28
var
  form:Tform2;
procedure TForm1.Button1Click(Sender: TObject);
begin
  if form=nil then  //也可写成if not Assigned(form) then 
  begin 
    form:=Tform2.Create(application);
  end;
  else
  begin
    if form.WindowState=wsMinimized then
    begin
      ShowWindow(form.Handle,SW_SHOWNORMAL);
      if (not form.Visible ) then //打开,但不可见
      begin
         form.Visible :=True;
         form.BringToFront;
         form.SetFocus ;
         Exit;
      end;
    end;
  end;
  form.Show;
end;
原创粉丝点击