图片框导入问题C#

时间:2017-05-02 18:37:37

标签: c# picturebox

导入选项不适用于C#中的picturebox。

enter image description here

导入按钮未生成浏览选项。

如何在项目文件夹中写(如何缩短路径?)

private void home_Load(object sender, EventArgs e))'
{
    /*pictureBox1.ImageLocation = "C:/..../documents/visual studio 2010/Projects/Janani/Janani/Properties/Energy.png";
    //pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
    pictureBox1.Location = new Point(100, 100);
    pictureBox1.Size = new Size(400, 200);

    pictureBox2.ImageLocation = "C:/..../documents/visual studio 2010/Projects/Janani/Janani/Properties/HandHolding.png";
    //pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
    pictureBox1.Location = new Point(200, 200);
    pictureBox2.Size = new Size(400, 200);*/

    pictureBox1.Image = Image.FromFile(@"C:/Users/Warrior/documents/visual studio 2010/Projects/Janani/Janani/Properties/Energy.png");
    pictureBox2.Image = Image.FromFile(@"C:/Users/Warrior/documents/visual studio 2010/Projects/Janani/Janani/Properties/HandHolding.png");
}

在代码中,第一个没有用。第二个好的!

1 个答案:

答案 0 :(得分:0)

从VS菜单栏中,您可以选择项目 - >项目属性(在底部),然后转到资源标签。从这里,您可以手动添加磁盘中的资源。然后你可以从这样的代码访问它们:

PictureBox pb = new PictureBox();
pb.Image = Properties.Resources.NameOfResource;

不要忘记设置其他PictureBox属性,如大小,位置等......