假设应用程序的路径是E:\application\appl1

this.groupBox1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\image\\a.jpg"); 

Application.StartupPath得路径就是.exe的路径,即 E:\application\appl1\bin\debug

如果不把image文件夹放到debug下,那么Application.StartupPath应该改为什么方式获取路径呢?

 

将image文件夹的所有文件选中,属性->生成操作,改为嵌入的资源。重新生成项目。

C# code
Assembly asm=Assembly.GetExecutingAssembly();
Stream imgStream
= asm.GetManifestResourceStream("WindowsApplication1.image.a.png");
pictureBox1.Image
= Image.FromStream(imgStream);


另外一种是在项目资源文件中添加你的所有图片,也是较简单和常用的方式。
pictureBox1.Image =Resources.A;

相关文章:

  • 2022-02-14
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2021-05-29
  • 2022-01-01
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案