Example of C # Mouse control control movement

Source: Internet
Author: User

//Click and hold the mouse button and the control follows the move. The cast does not move//the controls here can be replaced with other controls. usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacetest{ Public Partial classForm1:form {Private intAx, Ay;//define two variables to store the horizontal ordinate of the mouse         PublicForm1 () {InitializeComponent (); }        /// <summary>        ///Mouse First click Control, record mouse coordinates/// </summary>        /// <param ax= "int" >Mouse Horizontal</param>        /// <param ay= "int" >Mouse Ordinate</param>        Private voidButton1_mousedown (Objectsender, MouseEventArgs e) {Ax=e.x; Ay=e.y; }        /// <summary>        ///when the mouse moves, the control follows the mouse movement. Calculate with relative coordinates/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidButton1_mousemove (Objectsender, MouseEventArgs e) {            if(E.button = =mousebuttons.left) {button1. Left= button1. Left + (e.x-Ax); Button1. Top= button1. Top + (E.Y-ay); }        }    }}

Example of C # Mouse control control movement

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.