C# 按钮拖动效果
1. 2. 3. 4. 下面是拖动按钮和图片实例: public partial class Form1 : Form
{ Point oriPoint; Point picPoint; public Form1() { InitializeComponent(); } private void button1_MouseDown(object sender, MouseEventArgs e) { oriPoint = e.Location; } private void button1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Button b = sender as Button; b.Location = new Point(b.Location.X + (e.X - oriPoint.X), b.Location.Y + (e.Y - oriPoint.Y)); } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { picPoint = e.Location; } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { PictureBox pb=sender as PictureBox; pb.Location = new Point(pb.Location.X + (e.X - picPoint.X), pb.Location.Y + (e.Y - picPoint.Y)); } } } } |
|