We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Font rendering in Grid control

Hopefully you can shed some light on the rendering of fonts in the Grid control.

We are using the Grid control to display information originally authored in MS Excel (currently Office 2002). The expectation (by our users) is that the information displayed in the grid will be identical to how it lays out in Excel.

In this example, we are using the Tahoma font (sizes 8pt and 10pt). When we pull the information from the spreadsheet and display it in the grid (setting the cell's Font.Facename and Font.Size properties) the text actually displays slightly wider than it does in Excel. This ultimately causes text to get cut off in some cases.

I have done some research and have tried to set the Font.Unit property to GraphicsUnit.Display but all this does is display red cells containing the work "Exception".

If it makes a difference, we are using CoveredRanges to merge columns for this text.

Please let me know if I am missing something in what I am doing. If required, I can send a quick example.

Thanks,
Tom Murphy

4 Replies

HA haneefm Syncfusion Team April 18, 2007 09:54 PM UTC

Hi TJM,

Please try to provide us some more information on this issue. I tried to reproduce the issue, but couldn't. kindly provide us a small sample to reproduce the issue or modify any of our browser sample accordingly. This will help us to analyse the issue further.

Best regards,
Haneef


TJ TJM April 19, 2007 02:21 PM UTC

Haneef:

Thanks for your quick response.

I have attached a ZIP file that contains a BMP that demonstrates what I am seeing. You will notice that columns A and B are set to the same width (demonstrated by the thin red lines). But as you can see, the text in the form (Form1)displays much wider than that in Excel (the top cells) as demonstrated by the thicker red line.

I have also included the quick test app that I used to output Form1 in the image. In both cases cells A1 and B1 are merged and using a Tahoma 10 bold font.

Please let me know if there is any additional information that you require.

Thanks again for your response.
Tom Murphy

WindowsApplication313.zip


HA haneefm Syncfusion Team April 19, 2007 05:58 PM UTC

Hi Tom,

This can be resolved by handling the DrawCellDisplayText event and call the DrawText method to draw the text in a grid cell. Here is a code snippet

private void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style,e.ClipBounds, false);
}

Best regards,
Haneef


TJ TJM April 19, 2007 07:04 PM UTC

Haneef:

Thanks for the quick resolution. That seemed to do the trick.

The DrawText only seemed to required 5 paramters and the final "false" in your example was not needed but once that was removed things compiled and ran great.

Tom Murphy

Loader.
Live Chat Icon For mobile
Up arrow icon