将图像源设置为动态添加到 Table 布局面板的图片框

Set image source to picturebox which is added dynamically to Table Layout Panel

我按照此页面中的说明将控件插入到 tableLayoutPanel。 http://goo.gl/SVKf8D

我正在使用此代码尝试添加动态图片框并设置其来源:

    tableLayoutPanel1.Controls.Add(new PictureBox() { Image.FromFile(TableLayoutPanelTool.Properties.Resources.BaldGuyImage)}, 0, 0);

我无法通过这种方式将图片源插入图片框。

我需要的是:一种将图像设置为动态添加到 TableLayoutview 的图片框的方法

注意:可以提供来源 directly.Something 就像 source= C:/Projects/bin/debug

如果您已将图像添加到项目的资源文件中,则可以使用Properties.Resources class 访问它们。这种情况下可以直接把资源赋值成picturebox.image属性:

tableLayoutPanel1.Controls.Add(new PictureBox() { Image = TableLayoutPanelTool.Properties.Resources.BaldGuyImage}, 0, 0);

您可以阅读更多内容here and also from here