我正在尝试将 groupBox2 容器中的 pictureBox2 移动到另一个 groupBox1。问题是在那个容器中,还有一个pictureBox1,当我将pictureBox2移到pictureBox1上时,pictureBox2周围有一个白框。
总而言之,我想将pictureBox2 融合到pictureBox1 中。
这是我的代码,它结合了鼠标移动、向上和向下功能:
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
downPoint = e.Location;
pictureBox2.Parent = this;
pictureBox2.BringToFront();
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pictureBox2.Left += e.X - downPoint.X;
pictureBox2.Top += e.Y - downPoint.Y;
}
}
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
Control c = GetChildAtPoint(new Point(pictureBox2.Left - 1, pictureBox2.Top));
if (c == null) c = this;
Point newLoc = c.PointToClient(pictureBox2.Parent.PointToScreen(pictureBox2.Location));
pictureBox2.Parent = c;
pictureBox2.BackColor = Color.Transparent;
pictureBox2.Location = newLoc;
this.Refresh();
pictureBox2.BringToFront();
}
我可以将pictureBox2 移动到任何地方并为其分配父级,但我无法将其分配给pictureBox1 作为其父级,因为它仅将groupBox2 检测为其父级。
任何帮助将不胜感激。谢谢你。文森特