c# - Justify text with DrawString right -and- left -
let's have 200 pixels of space , want draw 2 strings it: - first string should left justified - right second string should right justified - not overlap if not both fit (then whatever string.trimming options say)
am going have measure each , draw manually, or drawstring have way support i'm trying without me reinventing wheel?
imagine \l , \r escapes did this, say
graphics.drawstring("\lfirst\rsecond", ...); and i'd wind like
"first second" at least that's i'd have happen (i know \l , \r not exist). there way?
i've ignored flags , instead i'm showing (roughly) how can align text. it's easy enough pick out text, split , draw 2 separate strings!
string text2 = "use textformatflags , rectangle objects to" + " align text in rectangle."; using (font font2 = new font("arial", 12, fontstyle.bold, graphicsunit.point)) { rectangle rect2 = new rectangle(150, 10, 130, 140); // create textformatflags word wrapping, horizontal center , // vertical center specified. textformatflags flags = textformatflags.horizontalleft | textformatflags.verticalcenter | textformatflags.wordbreak; // draw text , surrounding rectangle. textrenderer.drawtext(e.graphics, text2, font2, rect2, color.blue, flags); e.graphics.drawrectangle(pens.black, rect2); }
Comments
Post a Comment