I am confused about these two methods.
My understanding is that Graphics.DrawString() uses GDI+ and is a graphics-based implementation, while TextRenderer.DrawString() uses GDI and allows a large range of fonts and supports unicode.
My issue is when I attempt to print decimal-based numbers as percentages to a printer. My research leads me to believe that TextRenderer is a better way to go.
However, MSDN advises, "The DrawText methods of TextRenderer are not supported for printing. You should always use the DrawString methods of the Graphics class."
My code to print using Graphics.DrawString is:
if (value != 0)
e.Graphics.DrawString(String.Format("{0:0.0%}", value), GetFont("Arial", 12, "Regular"), GetBrush("Black"), HorizontalOffset + X, VerticleOffset + Y);
This prints "100%" for number between 0 and 1 and "-100% for numbers below zero.
When I place,
Console.WriteLine(String.Format("{0:0.0%}", value));
inside my print method, the value prints in the correct format (eg: 75.0%), so I am pretty sure the problem lies within Graphics.DrawString().
value
is being treated as an integer. I'd suggest breaking out your String.Format into a separate string variable so that you can set a breakpoint on the Graphics.DrawString and examine the contents of value and the resulting string during debugging. I seriously doubt this is Graphics.DrawString doing this. – Cerotype