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.
Unfortunately, activation email could not send to your email. Please try again.

GridGdiPaint and Italic Font

Thread ID:

Created:

Updated:

Platform:

Replies:

22194 Dec 6,2004 02:52 PM Dec 7,2004 07:45 AM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On December 6, 2004 02:52 PM

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

Administrator [Syncfusion]
Replied On December 6, 2004 04:09 PM

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;
if(e.Style.Font.Italic) 
	s += " ";
GridGdiPaint.Instance.DrawText(e.Graphics, s, rect, e.Style);

Administrator [Syncfusion]
Replied On December 7, 2004 05:38 AM

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

Administrator [Syncfusion]
Replied On December 7, 2004 07:45 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;