code.club
標題:
用滑鼠移動一個圖片
[打印本頁]
作者:
2266
時間:
2021-1-26 15:12
標題:
用滑鼠移動一個圖片
public partial class Form1 : Form
{
bool mouseDown = false;
int oldX;
int oldY;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
oldX = e.X;
oldY = e.Y;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if(mouseDown)
{
pictureBox1.Left += e.X - oldX;
pictureBox1.Top += e.Y - oldY;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;
}
}
}
歡迎光臨 code.club (https://code.club/)
Powered by Discuz! X3.2