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.
You could use [Drawing.Graphics.MeasureString()](http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx) to get the size of one of your glyphs.  

Then just check how many of them fit into your drawing area.