如何在Delphi中隐藏MDI子窗体? [英] How to hide a MDI Child form in Delphi?

查看:707
本文介绍了如何在Delphi中隐藏MDI子窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Delphi中隐藏MDIChild窗口?



我在MDI子窗体的FormClose()事件中使用这段代码,但似乎不工作:

 程序TfrmInstrument.FormClose(发件人:TObject; var Action:TCloseAction); 
begin
动作:= caNone;
ShowWindow(Handle,SW_HIDE);
frmMainForm.MDIChildClosed(Handle);
结束

我的子窗口被最小化而不是被隐藏。

解决方案

TCustomForm 中有一个受保护的过程定义为:

  procedure TCustomForm.VisibleChanging; 
begin
if(FormStyle = fsMDIChild)和Visible和(Parent = nil)然后
raise EInvalidOperation.Create(SMDIChildNotVisible);
结束

在您的MDI子窗口中覆盖它:

  procedure TMDIChildForm.VisibleChanging; 
begin
// :-P
end;

这是一个简单的例子



在阅读了Jeroen的评论后,我尝试了另一种解决方案,但是有一点闪烁:

  procedure TMDIChildForm.VisibleChanging; 
begin
if Visible then
FormStyle:= fsNormal
else
FormStyle:= fsMDIChild;
结束

也许这适用于所有Windows版本。



PS:我没有发现Windows 2k3SP2 x86和Windows 7 Ultimate x86上的第一个解决方案有任何问题


How can I hide a MDIChild window in Delphi?

I'm using this code in FormClose() event of my MDI children, but it doesn't seem to work:

procedure TfrmInstrument.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caNone;
  ShowWindow(Handle, SW_HIDE);
  frmMainForm.MDIChildClosed(Handle);
end;

My child window is minimized instead of being hidden.

解决方案

There is a protected procedure in TCustomForm defined as:

procedure TCustomForm.VisibleChanging;
begin
  if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then
    raise EInvalidOperation.Create(SMDIChildNotVisible);
end;

Override it in your MDI child windows as:

procedure TMDIChildForm.VisibleChanging;
begin
  // :-P
end;

Here's a simple example

After reading Jeroen's comment, I tried another solution which works as well, but with a little flickering:

procedure TMDIChildForm.VisibleChanging;
begin
  if Visible then
    FormStyle := fsNormal
  else
    FormStyle := fsMDIChild;
end;

Maybe this works on all Windows versions.

PS: I didn't find any problem with the first solution on Windows 2k3SP2 x86 and Windows 7 Ultimate x86

这篇关于如何在Delphi中隐藏MDI子窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆