有沒有辦法將外部字體定義爲新的System.Drawing.FontFamily
?我嘗試使用此代碼:System.Drawing.FontFamily不接受基於Uri的字體
FontFamily robotoLight = new FontFamily(new Uri("pack://application:,,,/"),
"./Fonts/#Roboto Light");
,並顯示此錯誤:
Cannot convert from
System.Uri
tostring
我意識到,我一直在使用不同的參考和接受Uri
是System.Windows.Media.FontFamily
的一個,所以也沒有工作。
我研究並發現,定義自定義字體的方法是使用PrivateFontCollection.AddFontFile
,但它使用字體的絕對路徑,如回答here。
我的字體當前位於項目內的fonts
文件夾中,並且構建爲包含在.exe
文件中,因此絕對路徑對我來說是不可行的。
,我需要使用System.Drawing
而不是System.Windows.Media
因爲我創建一個自定義MessageBox
你肯定「的Roboto光」是字體的名稱,而不是隻是名字文件?試試「./Fonts/#Roboto」。 – mm8
@ mm8我確定。我一直在項目的其他部分使用它。我通過使用字體安裝程序 – Swellar
檢查它哦,System.Drawing.FontFamily不理解pack URI。 – mm8