滑鼠拖動 移動座標

來源:互聯網
上載者:User

標籤:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 滑鼠拖動移動座標{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private bool isok ;        private int x; //滑鼠點下去的橫座標        private int y;//滑鼠點下去的縱座標        private int cx;        private int cy;        private void Form1_MouseDown(object sender, MouseEventArgs e) //點下去        {            isok = true;            x = Cursor.Position.X; //滑鼠點下去時候表單的橫座標            y = Cursor.Position.Y;//滑鼠點下去時候表單的縱座標            cx = this.Location.X;//表單初始橫座標            cy = this.Location.Y;//表單初始縱座標                    }        private void Form1_MouseUp(object sender, MouseEventArgs e)//鬆開        {            isok = false;        }        private void Form1_MouseMove(object sender, MouseEventArgs e)//移動        {            if(isok)            {                int movex = Cursor.Position.X; //移動過程的橫座標                int movey = Cursor.Position.Y;//移動過程的縱座標                this.Location = new Point(cx+movex-x,cy+movey-y); //初始座標+移動的座標-滑鼠最開始點下去的座標                           }        }         }}

  

滑鼠拖動 移動座標

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.