c#中 pictureBox控件里的image在picturebox中移动

就是picturebox控件里的image,在image中移动,而不是整个picturebox在form1窗体上移动

第1个回答  2011-03-27
private bool isMouseDown = false;
private Point mouseOffset; //记录鼠标指针的坐标
private void PicBox_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset.X = e.X;
mouseOffset.Y = e.Y;
isMouseDown = true;
}
}
private void PicBox_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
int left = PicBox.Left + e.X - mouseOffset.X;
int top = PicBox.Top + e.Y - mouseOffset.Y;
PicBox.Location = new Point(left,top);
}
}
private void PicBox_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}追问

…别捣乱,谢谢

追答

picturebox外面再加个picturebox 不就可以了吗

第2个回答  2011-03-27
public Form1()
{
InitializeComponent();

timer1.Enabled = true;

}

static int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = 100;

i = i + 10;

Image newImage = Image.FromFile(@"D:\0133583.jpg");
Graphics g = pictureBox1.CreateGraphics();

g.DrawImage(newImage,i,10);

}本回答被提问者采纳
相似回答