When programming, sometimes, for the purpose of need, the form's BorderStyle will be set to bsNone, that is, the untitled form. But in this way, because without the title bar, you cannot drag the form. In fact, we only need to use the following method to smoothly drag the form.
Added to the OnMouseDown event
OldX:=x;
OldY:=u;
Added to the OnMouseMove event
Form1.Left:=Form1.Left+x-Oldx;
Form1.Top:=Form1.Top+y-Oldy;
##1 code creation is as follows:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y,Integer);
procedure FormMouseMove(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y,Integer);
Private
{Private declarations}
public
Private declarations}
end;
var
Form1:TForm1;
OldX,OldY:integer; //Define global variables
Implementation
$R *.DFM}
procedure TForm1.FormMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y:Integer);
Begin
OldX:=x;
OldY:=y;
end;
procedure TForm1.FormMouseMove(Sender:TObject;Button:TMouseButton
Shift:TShiftState;X,
Y:Integer);
Begin
if ssleft in shift then //Press the left mouse button
Begin
Form1.Left:=Form1.Left+x-Oldx;
Form1.Top:=Form1.Top+y-Oldy;
end;
end;
end.
The code of chemos was tested and passed in Delphi5.0 and Win98 SE.