Question: Given a number of pixels (say: 300) and a Font (fixed type, fixed size, like Consolas), how could I determine the maximum number of characters that I could draw with **GDI+**?

The text won't be written to a Label or such, but drawn using GDI+:

```
public void DrawString( string s, Font font, Brush brush, 
    RectangleF layoutRectangle, StringFormat format );

```

But I want to perform certain text operations before drawing, hence why I'd like to figure out the maximum number of chars I can safely output.

Answer: 
There is also [TextRenderer.MeasureText()](http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.measuretext.aspx), which produces a different result (this is what is used when drawing windows controls, so it is generally more accurate). 

There is a discussion on SO somewhere about it, but I cannot find it at the moment.

**Edit:** [This MSDN Article](http://msdn.microsoft.com/en-gb/magazine/cc751527.aspx) goes a little more in depth.
Although this is a late reply, I came across the same issue.

I think the answer to your question is inside your question. The function DrawString function you mention has facilities to automatically trim long strings. Have a look at the docs <http://msdn.microsoft.com/en-us/library/19sb1bw6.aspx>.

The function will trim the string so that it fits into the layout rectangle. You have to set the trimming property of the stringformat object you pass as parameter to something other than none.