图片框导入问题 C#

A picturebox import issue C#

导入选项不适用于 C# 中的图片框。

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

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

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");
}

在代码中,第一个不起作用。第二个还行!

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

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

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