不多说 效果你自己试试去..
namespace WindowsMove
{
public partial class Form1 : Form
{
梁喊 public Form1()
{
InitializeComponent();
}
private int x;
private int y;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
租虚 {
x = e.X;
y = e.Y;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pictureBox1.Left += e.X - x;
pictureBox1.Top += e.Y - y;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if 橡型野(pictureBox1.Location.X <= 0)
{
pictureBox1.Location = new Point(1, pictureBox1.Location.Y);
}
if (pictureBox1.Location.X >= (this.Width - pictureBox1.Width))
{
pictureBox1.Location = new Point((this.Width - pictureBox1.Width - 1), pictureBox1.Location.Y);
}
if (pictureBox1.Location.Y <= 0)
{
pictureBox1.Location = new Point(pictureBox1.Location.X, 1);
}
if (pictureBox1.Location.Y >= (this.Height - pictureBox1.Height - 28))
{
pictureBox1.Location = new Point(pictureBox1.Location.X, (this.Height - pictureBox1.Height - 29));
}
}
}
}
}