I need to write some fixed-width font (i.e Courier New or Consolas) text to a .net Winforms window in the Paint event – not using a label or any other winforms control – rather using a graphics object method to render the text onto the form’s client area.
I am having difficulty aligning text on different lines under headings even though it is fixed width font. How can I get a precise measurement of the width of a single character in the fixed-width font? How can I get 2 lines to print out aligned horizontally in successive text out calls?
For example:
Heading 1 Heading 2
Short Other text A bit longer Still aligned?
I need a separate call to render each cell of text under Heading 2. For argument’s sake – let’s say column 1 items are printed in black and column 2 are printed in blue – we can’t use the same text out call for the entire line.
Graphics.MeasureStringmay be what you are looking for.