打印本文 打印本文 关闭窗口 关闭窗口
控件移动类的实现之二
作者:武汉SEO闵涛  文章来源:敏韬网  点击数6986  更新时间:2009/4/23 18:30:39  文章录入:mintao  责任编辑:mintao
  FPointRec.RightMid:=TDragPoint.Create(nil);

  FPointRec.RightMid.Cursor:=crSizeWE;

  FPointRec.ButtonMid:=TDragPoint.Create(nil);

  FPointRec.ButtonMid.Cursor:=crSizeNS;

  SetPointParent(PointParent);

end;

//------当前控件事件处理-------------------------

//处理点下的事件

procedure TDragClass.ConMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

var TempCon:TControl; R:TRect;

begin

  if Button=mbLeft then

  begin

       isDown:=True;

       GetCursorPos(PrevP);

  end;

   TempCon:=TControl(Sender);

   SetPointParent(TempCon.Parent);

   R.Left:=TempCon.Left;

   R.Top:=TempCon.Top;

   R.Right:=TempCon.Left+TempCon.Width;

   R.Bottom:=TempCon.Top+TempCon.Height;

   MoveX:=0; MoveY:=0;

   SetPointPos(R);

   SetPointvisible(true);

   SetCurActiveCon(TempCon);

end;

//处理当前控件移动的消息

procedure TDragClass.ConMouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

var offsetX,offsetY:integer; con:TControl;

    r:TRect;

begin

  if isDown and (Shift=[ssLeft])then

  begin

     GetCursorPos(nextP);

     offsetX:=NextP.X-PrevP.X;

     offSetY:=NextP.Y-PrevP.Y;

     Con:=TControl(Sender);

     if not FisMoveStep then

     begin

       Con.Left:=Con.Left+offSetX;

       Con.Top:=Con.Top+offSetY;

     end

     else begin

       MoveX:=MoveX+offsetX;

       MoveY:=MoveY+offsetY;

       if Abs(MoveX)>=FMoveStep then

       begin

         Con.Left:=Con.Left+MoveX;

         MoveX:=0;

       end;

       if Abs(MoveY)>FMoveStep then

       begin

         Con.Top:=Con.Top+MoveY;

         MoveY:=0;

       end;

     end;

     R.Left:=Con.Left;

     R.Top:=Con.Top;

     R.Right:=Con.Left+Con.Width;

     R.Bottom:=Con.Top+Con.Height;

     SetPointPos(R);

     prevP:=nextP;

  end;

end;

//处理当前控件鼠标弹起的消息

procedure TDragClass.ConMouseUp(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

   isDown:=False;

end;

//------------------------

 //设置八个点的父子关系

procedure TDragClass.SetPointParent(PointParent: TWinControl);

begin

   FPointRec.LeftTop.Parent:=PointParent;

   FPointRec.LeftBottom.Parent:=PointParent;

   FPointRec.RightTop.Parent:=PointParent;

   FPointRec.RightButton.Parent:=PointParent;

   FPointRec.LeftMid.Parent:=PointParent;

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

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