c# - How to get the exact Font out of Fontfamily? -
i want create picturebox adapts shape string of font. need can later create texts , lay on axwindowsmediaplayer control.
therefore created following class:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.drawing; namespace myproject { class shapedpictureboxes : picturebox { public shapedpictureboxes() { this.paint += this.shapedpaint; } void shapedpaint(object sender, painteventargs e) { system.drawing.drawing2d.graphicspath graphicspath = new system.drawing.drawing2d.graphicspath(); font font = new font("arial", 14f); float emsize = e.graphics.dpiy*font.size/72; graphicspath.addstring(text, new fontfamily("arial"), (int)system.drawing.fontstyle.regular, emsize, new point(0,0), new stringformat()); e.graphics.drawstring(text, font, brushes.red, new point(0, 0)); this.region = new region(graphicspath); } public string text = "here comes sun, doo da doo do"; } }
the problem is, "graphics.drawstring" not match graphicspath.addstring, because fontfamily isn't same font. how can match them?
so: how can convert fontfamily font or viceversa?
this how looks like:
you need account fact font
size specified in units of points, addstring()
size specified in device units.
you can convert units follows:
font font = new font("arial", 14f, fontstyle.bold); float emsize = e.graphics.dpiy * font.size / 72; // here's conversion. graphicspath.addstring(text, new fontfamily("arial"), (int)system.drawing.fontstyle.bold, emsize, new point(0, 0), new stringformat());
note i'm passing calculated emsize
addstring()
instead of passing 14f
.
Comments
Post a Comment