If you develop graphics or multimedia applications, you may be moving the form for how to do not use the title bar of the form. In fact, you can use the Customer area that drags the form with a mouse. Method One is the following is the most common method to complete the above function: add the following process declaration in the form of the form: Procedure Wmnchittest; Message Wm_nchittest; then add the following code in the Implementation section: Procedure TFORM1 {or you define FORM name} .wmnchittest (var msg: twmnchittest); BegindefaultHandler (MSG); if msg.result: = htclient kil.result: = HTCAPTION; END; This method makes Windows when you click on the Form Customer Click on the title bar. Method 2 The following is another method of implementing a normal form with a mouse. procedure TForm1.FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); beginif (ssLeft in Shift) then beginReleaseCapture; SendMessage (Form1.Handle, WM_SYSCOMMAND, SC_MOVE 1,0); end; end; above method Imperfectness When the option to display its contents in the Dragon Window is canceled, let's see what will happen. This is a setting for the Windows window, you can find this attribute in the Start Menu -> Settings -> Folder Items -> View -> Advanced Settings. In Windows 95, you need to modify the registry. When this property is set to invalid, the window will become a square contour when dragging the form. Maybe you use an irregular form, but it still displays the outline. When you want your form to stop on the edge of the screen (such as: Winamp, when you drag the form to a certain location on the top of the screen, the form is close to the top of the screen), if you use the second Method, before the mouse button is released, you will not be able to process the form position and cannot process the docking problem. Below I will solve two problems in a simple method: First, no matter where you set, you do not display the contour line when drag the form; second, the position detection is performed when the form is moved, and the position is appropriately docked at a certain time A specific location. Many people may have solved these problems, but maybe the following code will help you. Method 3 The following code can be copied directly to Delphi, provided that you save Form1 as umain.pas, form2 is udock.pas. The event used is: OnMousedown, OnMousemove, OnMouseup, OnShow (Form1). This is a method of moving the form according to the mouse, contains two forms, umain, and udock (Form1, and Form2). FORM2 is open via Form1 and can be docked at the bottom of Form1. After docking, FORM2 will move with Form1 until you move Form2.
Form1unit uMain; interface usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; typeTForm1 = class (TForm) procedure FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormShow (Sender: TObject); private {Private declarations } publicDocktoForm: Boolean; {Public declarations} end; varForm1: TForm1; CanMove, CanMoveX, CanMoveY: Boolean; oldX, oldY: Integer; F1X, F1Y, F2X, F2Y: integer; WorkArea: TRect; implementation uses uDock; {$ R * .DFM} procedure TForm1.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); beginCanMoveX: = true; CanMoveY: = true; CanMove: = true; oldX: = X; oldY: = Y; if DockToform THEN BEGINF1X: = form1.left; f1y: = form1.top; f2x: = form2.Left; f2x: = form2.top; end; end; procedure tform1.formmousemove (sender: Tobject; shift: TshiftState; x, y: integer; beginif (canmove) thnbeginif canmovex thenform1.left: = form1.Left (x - Oldx); if canmoveyim1.top: = form1.top (Y - oldy); // this Section latches to the topif (Form1.top
// this section latches to the Right Sideif (Form1.Left> Workarea.right-form1.width-10) And (Form1.LiDTH 10) Thenbegin Form1.Left: = Workarea.right- Form1.width; if (X-Oldx> 10) or (X-Oldx <-10) Thencanmovex: = true; Form1.Height-Form2.Height-10) and (form1.top procedure TForm1.FormShow (Sender: TObject); begin // Get Work Area ParametersSystemParametersInfo (SPI_GETWORKAREA, 0, @WorkArea, 0); Form2.Show; end; end.Form2unit uDock; interface usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; typeTForm2 = class (TForm) procedure FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer ); procedure FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private {Private declarations} public {public declarations} end; varForm2: TForm2; CanMove, CanMoveX, CanMoveY, DocktoForm: Boolean; oldX, oldY: Integer; implementation uses uMain; {$ R * .DFM} procedure TForm2.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); beginCanMoveX: = true; CanMoveY: = true CANMOVE: = true; oldx: = x; oldy: = y; end; procedure tForm2.FormMouseMove (Sender: Tobject; Shift: tshiftstate; x, y: integ r); beginif (canmove) The begin if can channel: = form2.Left (x - Oldx); if canmovey lifeform2.top: = form2.top (y - oldy); // this section latches to the the TOPIF (Form2.top