gpt4 book ai didi

c# - Windows 窗体 :picture box manual drag operation over image solution?

转载 作者:行者123 更新时间:2023-11-30 12:10:34 25 4
gpt4 key购买 nike

您好,我写了一个代码,可以在 winform 中拖动图片框,这是我的代码:

   private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{

pictureBox1.Top=(56 * ((pictureBox1.Top + (e.Y - firsty)) / 56) + 3); //this for the correction of location of picture box
isdragging[0] = false;

}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isdragging[0] = true;
firstx = e.X;
firsty = e.Y;
changeclickingstatus(pictureBox1);//this about my program
for (sbyte i = 0; i < (sbyte)20; i++)//this about my program
{
clickindex[i] = (sbyte)1;//this about my program
}
clickindex[0] = (sbyte)0;//this about my program
dragtop = (sbyte)(pictureBox1.Top/56);//this about my program
}



private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isdragging[0])
{

if (pictureBox1.Location.Y + (e.Y - firsty) < 0)
{
pictureBox1.Top = 0;//these are the limits of dragging

}
else if (pictureBox1.Location.Y + (e.Y - firsty) > 290)
{
pictureBox1.Top = 290;//these are the limits of dragging

}
else
{



pictureBox1.Top = pictureBox1.Top + (e.Y - firsty);

}


if (pictureBox1.Location.X + (e.X - firstx) < 6)
{
pictureBox1.Left = 6;//these are the limits of dragging
}
else if (pictureBox1.Location.X + (e.X - firstx) > 280)
{
pictureBox1.Left = 280;//these are the limits of dragging
}
else
{
pictureBox1.Left = pictureBox1.Left + (e.X - firstx);

}

}
}

我对 picturebox 2 有相同的代码,我的问题是:当我将我的第一张图片拖到第二张时,它会越过它并且代码正常工作,但是当我将第二张图片框拖到第一张图片框时,第二张图片框位于第一张图片下方!有这个属性吗?

最佳答案

您可以使用 BringToFront()方法:

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.BringToFront();
/**/
}

private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
pictureBox2.BringToFront();
/**/
}

关于c# - Windows 窗体 :picture box manual drag operation over image solution?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17969004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com