C# PictureBox - 无法使其工作
我在 C# 中显示 PictureBox 时遇到问题。我有两种形式。在我的主窗体中,我调用 PictureBox 所在的另一个窗体。
这就是我调用第二个表单的方式:
frmODeck oDeck = new frmODeck();
oDeck.Show();
现在,这是我的第二个表单,PictureBox 位于主表单中,
namespace Shuffle_Cards
{
public partial class frmODeck : Form
{
private PictureBox picBox;
private Image image;
public frmODeck()
{
InitializeComponent();
}
private void frmODeck_Load(object sender, EventArgs e)
{
image = Image.FromFile("C:\\C2.jpg");
picBox = new PictureBox();
picBox.Location = new Point(75, 20);
picBox.Image = image;
picBox.Show();
}
public void getCards()
{
}
}
}
我做错了什么,或者我错过了什么?
谢谢
I'm having trouble displaying a PictureBox in C#. I have two forms. In my main form I'm calling the other form, where the PictureBox is located.
This is how I am calling the second form:
frmODeck oDeck = new frmODeck();
oDeck.Show();
Now, this is my second form, where the PictureBox is located from main form
namespace Shuffle_Cards
{
public partial class frmODeck : Form
{
private PictureBox picBox;
private Image image;
public frmODeck()
{
InitializeComponent();
}
private void frmODeck_Load(object sender, EventArgs e)
{
image = Image.FromFile("C:\\C2.jpg");
picBox = new PictureBox();
picBox.Location = new Point(75, 20);
picBox.Image = image;
picBox.Show();
}
public void getCards()
{
}
}
}
What am I doing wrong, or what am I missing?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图片框控件需要添加到它应属于的顶级控件的控件集合中 - 在本例中是表单本身。相关:
Control.Controls
。替换:
为:
The picture-box control needs to be added to the control-collection of the top-level control it should belong to - in the case, the form itself. Relevant:
Control.Controls
.Replace:
with:
在你执行 picBox.Show(); 之前,您需要将其添加到您正在加载的窗口的控件中,并使用提供的代码@Ani:
应该可以!
Befor you do a picBox.Show(); , you need to add it to the Controls of the window you are loading, with the code @Ani provided:
That should do it!