Form.WindowState := wsMaximized;
在主屏幕上最大化普通 TForm时,属性 Left 为 -8 , Width 为 eg 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 时,会有间隙。为什么?