-->

移动形式的无边框风格(Move form without border style)

2019-06-25 06:37发布

如何移动一个无国界的形式? 我试图寻找在互联网上,但没有。 非常感谢。

Answer 1:

你可以使用任何包含的控制,包括本身拖动形式。

使用下面的示例中,您可以通过点击画布上并拖动移动窗体。 你可以通过把在面板的MouseDown事件相同的代码,这将让你创建你自己的伪标题栏做的窗体上的面板相同。

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const
  SC_DRAGMOVE = $F012;
begin
  if Button = mbLeft then
  begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
  end;
end;


Answer 2:

如果你的意思是通过鼠标拖动窗口,你可以重写WM_NCHITTEST消息处理和返回HTCAPTION的阻力区域。 下面将对于insance上部30个像素内拖动窗口:

type
  TForm1 = class(TForm)
  private
  protected
    procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  end;

..

procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
var
  Pt: TPoint;
begin
  Pt := ScreenToClient(SmallPointToPoint(Message.Pos));
  if Pt.Y < 30 then
    Message.Result := HTCAPTION
  else
    inherited;
end;


文章来源: Move form without border style