TForm最大化的左偏移-8来自哪里

时间:2016-08-09 11:02:45

标签: delphi delphi-10-seattle tform

当在主屏幕上通过Form.WindowState := wsMaximized;最大化普通TForm时,属性Left是-8,Width是例如Screen.Monitors[0].BoundsRect.Width+8

当我想通过'Form.Top,.Left,.Width,.Height'将Forms绝对位置设置为活动的Monitors WorkingArea时,由于缺少8个像素,总会有间隙。

来自哪个方向的额外偏移量为8,为什么有必要?

我的测试表格(带有一个切换一些定位状态的按钮)

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    FState: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  LBRect,
  LWRect,
  LFCRect,
  LFBRect: TRect;
begin
  LBRect  := Screen.Monitors[0].BoundsRect;
  LWRect  := Screen.Monitors[0].WorkareaRect;
  LFCRect := Self.ClientRect;
  LFBRect := Self.BoundsRect;

  case FState of
    0:
    begin
      Top := 100;
      Left := 100;
      Width := 800;
      Height := 600;
    end;
    1:
    begin
      WindowState := wsMaximized;
    end;
    2:
    begin
      WindowState := wsNormal;
    end;
    3:
    begin
      Self.Top := LBRect.Top;
      Self.Left := LBRect.Left;
      Self.Width := LBRect.Width;
      Self.Height := LBRect.Height;
    end;
    4:
    begin
      Self.Top := LWRect.Top;
      Self.Left := LWRect.Left;
      Self.Width := LWRect.Width;
      Self.Height := LWRect.Height;
    end;
  end;

  Inc(FState);
  FState := FState mod 5;
end;

end.

将状态设置为3或4时,会有间隙。为什么呢?

0 个答案:

没有答案