I'm drawing the text from a textbox using GDI; however, I'm trying to create my textbox such that it reflects the same amount of space that I am drawing to in GDI. So, for some X amount of width in GDI, I would like for the length of the string in the textbox to not be able to exceed this width.
To draw the string in GDI, I'm using the following:
Font font = new Font("Lucidia Console", 8, GraphicsUnit.Point);
StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone();
g.DrawString(textFromTextbox, font, Brush, layoutRect, sf);
As for the textbox, I measure the string as characters are entered:
Font font = new Font("Lucidia Console", 8, GraphicsUnit.Point);
Size lineSize = TextRenderer.MeasureText(textbox.Text, font);
Size charSize = TextRenderer.MeasureText(e.KeyChar.ToString(), font);
if( charSize + lineSize > MAX_LINE_SIZE )
//Other stuff;
I have the textbox itself using Lucidia Console 8pt as the font as well.
So, then the trouble becomes making a textbox of X width that's the same width as the width I'm drawing to in GDI.
I've run into all kinds of discussions about glyphs, em-size/pixel ratios, and other topics but with little resolve.
Any ideas?