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