繁体   English   中英

如何在 C# 中的图片框上显示图片框?

[英]How do I display a PictureBox on a PictureBox in C#?

我想在图片框上显示一个图片框。 我有一个“母亲”图片框和旁边的按钮。 每次单击按钮时,都会在“母亲”上显示一个新的图片框。 我已经创建了这样的图片框:

PictureBox newPictureBox = new PictureBox();
newPictureBox.Location = new Point(x:30,y:30);
newPictureBox.BackColor = Color.Red;
newPictureBox.Visible = true;
newPictureBox.Height = 200;
newPictureBox.Width = 200;

现在我不知道如何向用户显示它。 我尝试使用 .Show() 和

调用父控件集合的 GetChildIndex 和 SetChildIndex 方法。

我也试过了。 要么我不知道如何称呼它,要么就是不起作用。 一直在寻找解决方案太久了。 有没有人知道如何在该图片框顶部显示该图片框?

结果,我忘了将图片框添加到“母亲”图片框。 我添加了 1 行:

motherPictureBox.Controls.Add(newPictureBox);

所以现在我的代码如下所示:

PictureBox newPictureBox = new PictureBox();
newPictureBox.Location = new Point(x:30,y:30);
newPictureBox.BackColor = Color.Red;
newPictureBox.Visible = true;
newPictureBox.Height = 200;
newPictureBox.Width = 200;
motherPictureBox.Controls.Add(newPictureBox);

不需要把它提前,我只是忘记添加它......

您需要将新的图片框添加到表单的控件中

PictureBox NewPictureBox = new PictureBox();
NewPictureBox.BackColor = Color.Red;
NewPictureBox.Location = MotherPictureBox.Location;
NewPictureBox.Size = MotherPictureBox.Size;
this.Controls.Add(NewPictureBox);
NewPictureBox.BringToFront();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM