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:

enter image description here


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -