在Delphi中,如果您想要最大化一个没有标题栏的窗体,可以使用以下方法:
OnCreate
事件中,设置窗体的BorderStyle
属性为bsNone
,以移除窗体的边框和标题栏。procedure TForm1.FormCreate(Sender: TObject);
begin
Self.BorderStyle := bsNone;
end;
WndProc
方法,以便在接收到WM_NCLBUTTONDBLCLK
消息时最大化窗体。procedure TForm1.WndProc(var Message: TMessage);
begin
if Message.Msg = WM_NCLBUTTONDBLCLK then
begin
if (Message.LParam and $FFF0) = HTCAPTION then
begin
Perform(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
Exit;
end;
end;
inherited;
end;
OnMouseMove
事件中捕获鼠标位置,并在OnMouseDown
事件中设置窗体的Capture
属性为True
。procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
FMousePos.X := X;
FMousePos.Y := Y;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
SetCapture(Handle);
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
ReleaseCapture();
end;
end;
OnMouseUp
事件中释放鼠标捕获。procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture();
end;
领取专属 10元无门槛券
手把手带您无忧上云