string s = this.gridControl1[2,2].Text; if(e.Style.Font.Italic) s += " "; GridGdiPaint.Instance.DrawText(e.Graphics, s, rect, e.Style);
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