如下图所示:

C# GetManifestResourceStream获取资源为null

specialFont.cs有个方法要访问“楷体_GB2312.ttf”资源,写法如下,却得到的是一个“null”百思不得其解,原来写错了:

String projectName = Assembly.GetExecutingAssembly().GetName().ToString();
Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(projectName+".Resources" +".楷体_GB2312.ttf");

应该写成一下:

String projectName = Assembly.GetExecutingAssembly().GetName().Name.ToString();
Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(projectName+".Resources" +".楷体_GB2312.ttf");

另外,“楷体_GB2312.ttf”的属性必须以 “嵌入的资源”作为资源文件。设置只需要在对应属性框设置就是了。




相关文章:

  • 2021-08-19
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-08-01
猜你喜欢
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案