C # Move and change control size

Source: Internet
Author: User

The code is relatively simple, not much to parse.

#regionMove a form to save dataPoint Mouseoff;//mouse Move position variable BOOLLeftflag;//whether the flag is left button BOOLLargeflag;//whether the flag changes width and height at the same time BOOLWidthflag;//whether the flag changes width BOOLHeightflag;//whether the flag changes height /// <summary> ///Mouse Movement/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidForm1_mousemove (Objectsender, MouseEventArgs e) {Point Mouseset=control.mouseposition; if(leftflag) {//Change the width and height if(largeflag) {intDW = Mouseset.x- This. location.x; intDH = mouseset.y- This. LOCATION.Y; This. Width =DW; This. Height =DH; } //Change Width Else if(widthflag) {intDW = Mouseset.x- This. location.x; This. Width =DW; } //Change Height Else if(heightflag) {intDH = mouseset.y- This. LOCATION.Y; This. Height =DH; } //Move Position Else{mouseset.offset (mouseoff.x, mouseoff.y);//set the position after the move This. Location =Mouseset; } } Else { //set the flag to change the width of the form if(( This. Location.x + This. Width-mouseset.x) <Ten&& ( This. LOCATION.Y + This. HEIGHT-MOUSESET.Y) <Ten) { This. Cursor =Cursors.sizenwse; Largeflag=true; } //set a flag that changes the width of the form Else if(( This. Location.x + This. Width-mouseset.x) <Ten) { This. Cursor =Cursors.sizewe; Widthflag=true; } //set the flag to change the height of the form Else if(( This. LOCATION.Y + This. HEIGHT-MOUSESET.Y) <Ten) { This. Cursor =Cursors.sizens; Heightflag=true; } //set the flag for the move position Else { This. Cursor =Cursors.Default; Largeflag=false; Widthflag=false; Heightflag=false; } } } /// <summary> ///mouse button down/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidForm1_mousedown (Objectsender, MouseEventArgs e) { if(E.button = =mousebuttons.left) {Mouseoff=NewPoint (-e.x,-e.y);//get the value of a variableLeftflag =true;//Click on the left button when the label is true; } } /// <summary> ///Mouse pop up/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidForm1_mouseup (Objectsender, MouseEventArgs e) { if(leftflag) {Leftflag=false;//label false after releasing the mouse; } } #endregion

C # Move and change control size

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.