Implementing a form with mouse movement (control)-"developing shareware with Delphi"-15.1 Task Manager

Source: Internet
Author: User

Private  //form movement; oldpos,newpos:tpoint;bmove:boolean;procedure Tform1.formmousedown (Sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer); Beginbmove:=true;oldpos:=clienttoscreen (Point (x, y)); End;procedure Tform1.formmousemove (Sender: TObject; Shift:tshiftstate; X,y:integer); beginif not bmove then Exit; Newpos:=clienttoscreen (Point (x, y)); left:=left+newpos.x-oldpos.x; Top:=top+newpos.y-oldpos.y;oldpos:=newpos;end;procedure Tform1.formmouseup (sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer); beginbmove:=false;end;

Expansion: This allows a control to be moved;

1 //variables2Ismousedown:boolean;//whether to drag or drop3Posx,posy:integer;//Drag the coordinates at the beginning4 5 procedureTform1.edt2mousedown (sender:tobject; Button:tmousebutton;6 shift:tshiftstate; X, Y:integer);7 begin8Ismousedown: = True;//tell the form I'm going to drag9PosX: = Mouse.cursorpos.x-edt2. Left;//where the record beginsTenPosY: = Mouse.cursorpos.y-edt2. Top;// One End; A  - procedureTform1.edt2mousemove (sender:tobject; Shift:tshiftstate; X, - Y:integer); the begin -   ifIsmousedown Then                          //Mouse is pressed state (to drag) -   begin -Edt2. Left: = Mouse.cursorpos.x-posx;//the new location +Edt2. Top: = Mouse.cursorpos.y-PosY; -   End; + End; A  at procedureTform1.edt2mouseup (sender:tobject; Button:tmousebutton; - shift:tshiftstate; X, Y:integer); - begin -Ismousedown: = False;//tell the form I'm done dragging . - End;
Control Move

Implementing a form with mouse movement (control)-"developing shareware with Delphi"-15.1 Task Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.