如何在 Delphi 中隐藏 MDIChild 窗口?
我在我的 MDI child 的 FormClose() 事件中使用这段代码,但它似乎不起作用:
procedure TfrmInstrument.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
ShowWindow(Handle, SW_HIDE);
frmMainForm.MDIChildClosed(Handle);
end;
我的子窗口被最小化而不是被隐藏。
最佳答案
TCustomForm
中有一个 protected 过程定义为:
procedure TCustomForm.VisibleChanging;
begin
if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then
raise EInvalidOperation.Create(SMDIChildNotVisible);
end;
在您的 MDI 子窗口中将其覆盖为:
procedure TMDIChildForm.VisibleChanging;
begin
// :-P
end;
阅读 Jeroen 的评论后,我尝试了另一种同样有效的解决方案,但有一点闪烁:
procedure TMDIChildForm.VisibleChanging;
begin
if Visible then
FormStyle := fsNormal
else
FormStyle := fsMDIChild;
end;
也许这适用于所有 Windows 版本。
PS:我在Windows 2k3SP2 x86和Windows 7 Ultimate x86上没有发现第一个解决方案有任何问题
关于windows - 如何在 Delphi 中隐藏 MDI 子窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12178720/