我尝试从内存中添加字体(嵌入式资源),并将它用于我的windows窗体(c++/cli)应用程序.代码正在工作,但是当指定的字体没有安装在计算机上时,textbox使用的是默认字体而不是我的自定义字体。CompatibleTextRenderingDefault设置为true。
System::Drawing::Text::PrivateFontCollection^ privateFont = gcnew System::Drawing::Text::PrivateFontCollection();
IO::Stream^ fontStream = Reflection::Assembly::GetExecutingAssembly()->GetManifestResourceStream("textfont.otf");
array<Byte>^ fontData = gcnew array<Byte>(fontStream->Length);
fontStream->Read(fontData, 0, (int)fontStream->Length);
fontStream->Close();
pin_ptr<byte> fontAddress = &fontData[0];
privateFont->AddMemoryFont((IntPtr)fontAddress, fontData->Length);
this->TextBox_Username->Font = gcnew System::Drawing::Font(safe_cast<System::Drawing::FontFamily^>(privateFont->Families[0]), 9.749999F, System::Drawing::FontStyle::Bold);
this->TextBox_Password->Font = gcnew System::Drawing::Font(safe_cast<System::Drawing::FontFamily^>(privateFont->Families[0]), 9.749999F, System::Drawing::FontStyle::Bold);发布于 2017-11-10 11:33:30
可用于将字体加载到AddFontFile中的两种方法(AddFontFile、AddMemoryFont)都不完全支持OpenType字体。使用TrueType字体代替。
https://stackoverflow.com/questions/36986131
复制相似问题