One possible solution is to remove the border completely but then tell Windows that the edges of the window are to be considered sizing borders.
To do this, set BorderStyle
to bsNone
and respond to the WM_NCHITTEST
message:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
private
protected
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm5 }
procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
var
D: Integer;
P: TPoint;
begin
D := GetSystemMetrics(SM_CXSIZEFRAME);
P := Self.ScreenToClient(Message.Pos);
if P.Y < D then
begin
if P.X < D then
Message.Result := HTTOPLEFT
else if P.X > ClientWidth - D then
Message.Result := HTTOPRIGHT
else
Message.Result := HTTOP;
end
else if P.Y > ClientHeight - D then
begin
if P.X < D then
Message.Result := HTBOTTOMLEFT
else if P.X > ClientWidth - D then
Message.Result := HTBOTTOMRIGHT
else
Message.Result := HTBOTTOM;
end
else
begin
if P.X < D then
Message.Result := HTLEFT
else if P.X > ClientWidth - D then
Message.Result := HTRIGHT
end;
end;
end.
I'm not sure if this can be considered "best practices", however. Nor do I feel confident that there aren't any unwanted side effects, besides the obvious ones.
As always, you should be very careful when you do "unusual" things.