Loading image from relative path in Windows Forms

后端 未结 2 685
感动是毒
感动是毒 2020-11-29 11:26

I have an image in my application and i have a picture in my winforms

public static string Correct_Icons = @\"C:\\Users\\xyz\\Documents\\Visual Studio 2008\\         


        
2条回答
  •  自闭症患者
    2020-11-29 12:06

    For my program, Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location) returns C:\code\test\Junk\bin\Debug.

    cell.Value = Image.FromFile(
      Path.Combine (
         Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location),
         "Resources/warning_Icon"));
    

    Of course, usually you would embed the resources in your assembly unless you want to change them without a recompile.

提交回复
热议问题