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
close icon

GridGdiPaint and Italic Font

Using the GridGdiPaint.Instance.DrawText method to draw a single character using an italic font does not render the entire character. Please see the attached example. When clicking the GDIPlus button, the entire character is shown in the cell, but when clicking the GDI button "some" of the character is cutoff. Please Advise. Thanks, Steve ItalicZero1_6126.zip

3 Replies

AD Administrator Syncfusion Team December 6, 2004 09:09 PM UTC

Thank you for the sample. One way to see the text until we can get a release that has this fixed is to add a blank on the right if you are using Italics.
string s = this.gridControl1[2,2].Text;
	s += " ";
GridGdiPaint.Instance.DrawText(e.Graphics, s, rect, e.Style);

AD Administrator Syncfusion Team December 7, 2004 10:38 AM UTC

I would like to track the status of this bug, should I open a direct track incident? Thanks, Steve

AD Administrator Syncfusion Team December 7, 2004 12:45 PM UTC

Hi Steve, I looked into this. First, you need to make some changes to your code: private void gridControl1_DrawCell(object sender, GridDrawCellEventArgs e) { Rectangle rect; if (e.RowIndex == 2 && e.ColIndex == 2) { if (!blnGDIPlus) { //e.Style.Trimming = StringTrimming.None; //e.Style.TextMargins.Right += 2; //rect = this.gridControl1.RangeInfoToRectangle(GridRangeInfo.Cell(e.RowIndex,e.ColIndex),GridRangeOptions.MergeFloatedCells); rect = e.Renderer.GetCellLayout(e.RowIndex, e.ColIndex, e.Style).TextRectangle; GridGdiPaint.Instance.DrawText(e.Graphics,e.Style.FormattedText,rect,e.Style); e.Cancel = true; } } } You need to use the renderers TextRectangle instead of the complete area. Otherwise TextMargins will not be applied. This will give somewhat better results already, but the 0 is still clipped a bit. To avoid the clipping you can specify e.Style.Trimming = StringTrimming.None; Then the text will not be painted with GDI DrawText routine anymore and will instead be painted with ExtTextOut routine. But this might have some issues for longer text that is longer than the cell. Another improvemt is to set e.Style.TextMargins.Right += 2; That way the text gets a bit shifted to the left. DrawText and ExtTextOut use a bit a different logic for aligning the text and that is something you simply have to keep in mind when using these GDI routines. What I did now in our source code is the following: I added a DrawText overload that accepts an additional clipBounds argument and specifies the clip bounds of the text. When empty or same as textRectangle there will be no explicit clipping (but this does not affect DT_NOCLIP setting of GDI DrawText routine). If specified then output will be clipped by setting IntersectClipRect and DT_NOCLIP option is used for DrawText. So, with the next build you can then replace your routine as follows: private void gridControl1_DrawCell(object sender, GridDrawCellEventArgs e) { Rectangle rect; if (e.RowIndex == 2 && e.ColIndex == 2) { if (!blnGDIPlus) { rect = e.Renderer.GetCellLayout(e.RowIndex, e.ColIndex, e.Style).TextRectangle; GridGdiPaint.Instance.DrawText(e.Graphics,e.Style.FormattedText,rect,e.Style,e.Bounds); e.Cancel = true; } } } The DrawText rotine will be correctcly clipped then no matter if you specify StringTrimming.None or not. The changes I mentioned will be in the next build for Essential Suite. Stefan

Live Chat Icon For mobile
Up arrow icon