C# Windows 窗体应用映像找不到路径 [已关闭]

C# Windows Forms apps image cant find path [closed]

提问人:Akis 提问时间:11/17/2023 最后编辑:Daniel A. WhiteAkis 更新时间:11/17/2023 访问量:39

问:


这个问题似乎与帮助中心定义的范围内的编程无关。

6天前关闭。

int flag = 1;
private void button1_Click(object sender, EventArgs e)
{
   flag *= -1;
   if (flag == -1)
   {
      Bitmap b = new Bitmap("C:\\programming\\C#\\MusicMuseum\\MusicMuseum\\bin\\Debug\\party1.jpg");
      button1.Image = b;
   }
   else 
   {
      Bitmap b2 = new Bitmap("C:\\programming\\C#\\MusicMuseum\\MusicMuseum\\bin\\Debug\\party2.jpg");
      button1.Image = b2;
    }
}

你好,我做了一个程序,按钮应该改变背景图像。路径不起作用,有没有通用的方法来放置路径?

C# WinForms

评论

1赞 Daniel A. White 11/17/2023
将它们包含在资源中。
0赞 IVSoftware 11/17/2023
该文件需要在运行时位于已知位置。你可以喜欢这个答案:stackoverflow.com/a/72418567/5438626。或者,您可以将其标记为 ,然后检索它,如此答案所示。stackoverflow.com/a/73185764/5438626CopyToOutputDirectoryEmbedded Resource

答: 暂无答案