c# - How can i change in Graphics DrawString the text font size? -



c# - How can i change in Graphics DrawString the text font size? -

i'm using method draw text on form1:

private bool drawtext(bool draw, string texttodraw) { graphics g = this.creategraphics(); sizef size = g.measurestring(texttodraw, systemfonts.defaultfont,14); g.drawstring(texttodraw, font, brushes.red, picturebox1.location.x + (picturebox1.width / 2) - (size.width / 2), picturebox1.location.y - 30); homecoming draw; }

i tried set width 14 on sizef size lline didn't alter dize , thing did moving bit text it's location .

how can alter font size of text, , maintain perspective(if right word use) of text location ?

this how when not using width 14 @ text in center above picturebox1. want when alter text size kept in center now.

the text in reddish , it's in hebrew in case.

try using bigger font:

using (font bigfont = new font(systemfonts.defaultfont.fontfamily, 14, fontstyle.regular)) { sizef size = g.measurestring(texttodraw, bigfont, 14); g.drawstring(texttodraw, bigfont, brushes.red, picturebox1.location.x + (picturebox1.width / 2) - (size.width / 2), picturebox1.location.y - 30); }

do avoid using creategraphics, it's temporary drawing erased overlapping windows or minimizing form. cause flicker. utilize graphics object paint event , invalidate command update painting.

also, favor using textrenderer.drawtext , textrenderer.measuretext text renderings. drawstring should used printing paper.

c# .net winforms

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -