打印本文 打印本文 关闭窗口 关闭窗口
Delphi中的窗体移动
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2431  更新时间:2009/4/23 18:25:34  文章录入:mintao  责任编辑:mintao
  Form1.Left := WorkArea.Right-Form1.Width;
            if (X-OldX > 10) or (X-OldX < -10) then
            CanMoveX := true
            else
            CanMoveX := False;
            end;
            //This section latches to the TaskBar
            if DocktoForm then
            begin
            if (Form1.Top > WorkArea.Bottom-Form1.Height-Form2.Height-10) and
            (Form1.Top < WorkArea.Bottom-Form1.Height-Form2.Height+10) then
            begin
            Form1.Top := WorkArea.Bottom-Form1.Height-Form2.Height;
            if (Y-OldY > 10) or (Y-OldY < -10) then
            CanMoveY := true
            else
            CanMoveY := False;
            end;
            end
            else begin
            if (Form1.Top > WorkArea.Bottom-Form1.Height-10) and (Form1.Top <
            WorkArea.Bottom-Form1.Height+10) then
            begin
            Form1.Top := WorkArea.Bottom-Form1.Height;
            if (Y-OldY > 10) or (Y-OldY < -10) then
            CanMoveY := true
            else
            CanMoveY := False;
            end;
            end;

            if DocktoForm then
            begin
            Form2.Left := Form1.Left - (F1X-F2X);// + (X-OldX);
            Form2.Top := Form1.Top+Form1.Height;
            exit;
            end;
            //This section latches playlist in center of Form1
            if (Form2.Left > Form1.Left + ((Form1.Width div 2)-(Form2.Width div
            2))-10) and (Form2.Left < Form1.Left + ((Form1.Width div
            2)-(Form2.Width div 2))+10) and
            (Form2.Top > Form1.Top+Form1.Height-10) and (Form2.Top <
            Form1.Top+Form1.Height+10) then
            begin
            Form2.Left := Form1.Left + ((Form1.Width div 2)-(Form2.Width div 2));
            DocktoForm := True;
            F1X := Form1.Left;
            F1Y := Form1.Top;
            F2X := Form2.Left;
            F2Y := Form2.Top;
            end;
            end;
            end;
            procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
            Shift: TShiftState; X, Y: Integer);
            begin
            CanMove := false;
            end;
            procedure TForm1.FormShow(Sender: TObject);
            begin
            //Get Work Area Parameters
            SystemParametersInfo(SPI_GETWORKAREA, 0, @WorkArea, 0 );
            Form2.Show;
            end;
            end.


      Form2
            unit uDock;
            interface
            uses
            Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
            Dialogs;
            type
            TForm2 = 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;
            var
            Form2: 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);
            begin
            CanMoveX := true;
            CanMoveY := true;
            CanMove := true;
            OldX := X;
            OldY := Y;
            end;
            procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState;
            X, Y: Integer);
            begin
            if (CanMove) then
            begin
            if CanMoveX then
            Form2.Left := Form2.Left + (X - OldX);
   &nb

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口