c# - addFontFile from Resources -
i have added custom font using below code:
privatefontcollection pfc = new privatefontcollection(); pfc.addfontfile("c:\\path to\\yourfont.ttf"); label1.font = new system.drawing.font(pfc.families[0], 16, fontstyle.regular);
i added font file in resources. how add addfontfile
resources?
if included font in resources
try function
private void addfontfrommemory() { stream fontstream = this.gettype().assembly.getmanifestresourcestream("yourfont.ttf"); byte[] fontdata = new byte[fontstream.length]; fontstream.read(fontdata,0,(int)fontstream.length); fontstream.close(); unsafe { fixed(byte * pfontdata = fontdata) { pfc.addmemoryfont((system.intptr)pfontdata,fontdata.length); } } }
edited
how load resource assembly:(yournamespace.file.ttf)
stream fontstream = assembly.getexecutingassembly() .getmanifestresourcestream("windowsformsapplication1.sbadr.ttf");
my solution explorer:
Comments
Post a Comment