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: 
I read few sites and come up with solution as,

```
using (System.Drawing.Graphics graphics = CreateGraphics())
{
    System.Drawing.Size size = TextRenderer.MeasureText(graphics, id, e.Appearance.Font);
    if (size.Width > e.Column.Width)
    {
        int charFit = (int)(((double)e.Column.Width / (double)size.Width) * (double)id.Length);
        if (id.Length - charFit + 2 < id.Length)
        {
            e.DisplayText = string.Format("{0}{1}","...", id.Substring(id.Length - charFit + 2));
        }
    }
}

```

I did this changes in CustomDrawCell event of the DevExpress grid view.
Please let me know if you see any flaw in this solution.
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.