Moving a form without border.

Freerider
Freerider used Ask the Experts™
on
Hi all,

can anyone tell me how to make a form with [BorderStyle = bsNone] moveable? I am displaying an image on the form and don't want a border.

Thanks,
Freerider.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Very Simply try This.



interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
   private
   procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
 inherited;
 if Msg.Result = htClient then Msg.Result := htCaption;
end;



end.



If you want to show an image you can use a Timage component.

Best Regards.
Marcos.
Another way to show an image:

procedure TfrMenu.FormCreate(Sender: TObject);
begin
  bmpFondo := TBitmap.Create;
  bmpFondo.LoadFromFile( 'c:\pan\MyBmp.bmp' );
end;
procedure TfrMenu.FormDestroy(Sender: TObject);
begin
 bmpFondo.Free;
end;

procedure TfrMenu.FormPaint(Sender: TObject);
begin
   
   Canvas.Draw(163, 55, bmpFondo );
end;


Best Regards.
Marcos.
hello Freerider, you might try

procedure TForml.MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer);
Const SC_DragMove = $F012;
begin
  if (Button = mbLeft) then
  begin
  ReleaseCapture;
  Self.perform(WM_SysCommand, SC_DragMove, 0);
  end;

end;

the SC_DragMove is issued by the system after a htCaption, WM_NCHITTEST
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Commented:
procedure WMNCHitTest(var Msg : TMessage); message WM_NCHITTEST;

procedure TForm1.WMNCHitTest(var Msg : TMessage);
begin
  if GetAsyncKeyState(VK_LBUTTON) < 0 then
    Msg.Result := HTCAPTION
  else
    Msg.Result := HTCLIENT;
 end;

It makes windows think you are clicking on the title bar when you are clicking in the client area.

Author

Commented:
Thanks,

I'll let you know how I get on...
Hi Freerider,

put this code in either onMouseClick or onMouseDown for the form or the image or both

ReleaseCapture;
TForm(form1).perform(WM_SYSCOMMAND, $F012, 0);

Regards

Hill
Freerider:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial