C# 拖拽按鈕移動
阿新 • • 發佈:2019-02-11
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _20160119張老師作業 { public partial class Form1 : Form { Point p; public Form1() { InitializeComponent(); } private void button1_MouseDown(object sender, MouseEventArgs e) { p = e.Location; } private void button1_MouseUp(object sender, MouseEventArgs e) { p = e.Location; } private void button1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) this.button1.Location = new Point(this.button1.Left + (e.X - p.X), this.button1.Top + (e.Y - p.Y)); } } }