为什么我的MDIChild表单每次都不以wsMaximized状态打开?

问题描述 投票:-1回答:1

Delphi MDIChild窗口状态问题

我有一个带有MDI和子项的delphi项目。当我创建一个新的子窗体时,它在主窗体(子wsMaximized)上恰好占据了一个保留空间。

但是当创建另一个子窗体(不关闭第一个子窗体)时,第一个子窗体“失去了wsMaximized状态”。

恢复:每次都需要最大化子窗体,但是当打开第二个子窗体时,另一个子窗体的“ windowstate”将被更改。

第一个孩子:

procedure TfrmPrincipal.PosicionarForm(AForm: TForm);
var
  Rect: TRect;
begin
  GetWindowRect(Application.MainForm.ClientHandle, Rect);

  InflateRect(Rect, -2 * GetSystemMetrics(SM_CXBORDER),
    -2 * GetSystemMetrics(SM_CYBORDER));
  OffsetRect(Rect, -Rect.Left, -Rect.Top);

  AForm.BoundsRect := Rect;
end;

procedure TfrmPrincipal.actCadastroFornecedorExecute(Sender: TObject);
begin
    frmCadastroFornecedor := TfrmCadastroFornecedor.Create(Application);
    PosicionarForm(frmCadastroFornecedor);
    frmCadastroFornecedor.Show;
  svSub.Visible := False;
  SV.Opened := False;
end;

enter image description here

第二个孩子:

procedure TfrmPrincipal.actCadastroProdutosExecute(Sender: TObject);
begin
  frmCadastroProduto := TfrmCadastroProduto.Create(Application);
  PosicionarForm(frmCadastroProduto);

  frmCadastroProduto.Show;

  svSub.Visible := False;
  SV.Opened := False;
end;

enter image description here

编辑:

我创建了一个新项目,有3种形式。代码很简单,但是这种行为仍在继续。

主要形式:

 unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    screen11: TMenuItem;
    screen21: TMenuItem;
    procedure screen11Click(Sender: TObject);
    procedure screen21Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
unit2, unit3;

{$R *.dfm}

procedure TForm1.screen11Click(Sender: TObject);
begin
  form2 := tform2.Create(Application);
  form2.Show;
end;

procedure TForm1.screen21Click(Sender: TObject);
begin
form3 := tform3.Create(Application);
  form3.Show;
end;

end.

儿童1:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

end.

儿童2:

unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm3 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

end.
delphi vcl mdichild
1个回答
1
投票

经过一些反复试验(再一次举例说明complete的重要性,最小化,可重复性,例子是多么重要),我能够重现您所问的错误。如果您包含了.dfm文件,则实际问题早得多了。

现在,删除子表单之一后,表单的WindowStatewsMaximized变为wsNormal的问题。

当您从biMaximiseBorderIcons表格中删除Form2时,会发生这种情况>

治疗:选择Form3

我也建议您从主表单中删除BorderIcons.biMaximise。它似乎没有任何用处。

© www.soinside.com 2019 - 2024. All rights reserved.