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”的属性必须以 “嵌入的资源”作为资源文件。设置只需要在对应属性框设置就是了。





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM