Местене на форма
0 отговора
0 прегледа
Местене на форма
Някой искаше да мести формата с мишката. Ето един вариант.
unit MestiForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
SpBut : TSpeedButton;
procedure WMNCHITTEST(var Msg: TWMNCHitTest);
message WM_NCHITTEST;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMNCHITTEST(var Msg: TWMNCHitTest);
begin
Inherited;
with Msg do
with ScreenToClient(Point(XPos,YPos)) do
if not PtInRect(SpBut.BoundsRect, Point(X,Y)) then
Result := htCaption;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
SpBut := TSpeedButton.Create(Self);
with SpBut do
begin
Parent := Self;
Left := Form1.Left+Form1.Height-40;
Top := 2;
Width := 14;
Height := 14;
OnClick := Button1Click;
Caption := 'X';
Font.Style := [fsBold];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
end.
unit MestiForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
SpBut : TSpeedButton;
procedure WMNCHITTEST(var Msg: TWMNCHitTest);
message WM_NCHITTEST;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMNCHITTEST(var Msg: TWMNCHitTest);
begin
Inherited;
with Msg do
with ScreenToClient(Point(XPos,YPos)) do
if not PtInRect(SpBut.BoundsRect, Point(X,Y)) then
Result := htCaption;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
SpBut := TSpeedButton.Create(Self);
with SpBut do
begin
Parent := Self;
Left := Form1.Left+Form1.Height-40;
Top := 2;
Width := 14;
Height := 14;
OnClick := Button1Click;
Caption := 'X';
Font.Style := [fsBold];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
end.