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

独自空忆成欢 提交于 2019-12-11 11:07:31

问题


I followed instructions from this page to insert controls to tableLayoutPanel. http://goo.gl/SVKf8D

I am using this code to try to add a dynamic picturebox and set it's source:

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

I cannot insert image source to picturebox this way.

What I need: A way to set the image to the Picturebox that I have added dynamically to the TableLayoutview

note:it is ok to give source directly.Something like source= C:/Projects/bin/debug


回答1:


If you have added the image into project's resources file, you can access them using Properties.Resources class. In this case, you can directly assign the resource into picturebox.image property:

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

You could read more here and also from here



来源:https://stackoverflow.com/questions/31957081/set-image-source-to-picturebox-which-is-added-dynamically-to-table-layout-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!