Draw Image in header
hi!
i have a girdControl header with a image at right hand side in the header cell. I do as following:
if (e.RowIndex == 1 && e.ColIndex != 0)
{
e.Style.CellAppearance = GridCellAppearance.Raised;
if (e.ColIndex % 2 == 0)
{
string s = e.Style.Text;
e.Style.ImageList = ilDG;
e.Style.ImageIndex = 0;
e.Style.Text = " ";
//Draw the ColumnHeader cell in a Grid.
Rectangle crect = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Size.Width - e.Style.ImageList.ImageSize.Width, e.Bounds.Height));
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
//Draw the text in a Grid.
Rectangle irect = new Rectangle(new Point(e.Bounds.Right - e.Style.ImageList.ImageSize.Width, e.Bounds.Top + 2), e.Style.ImageList.ImageSize);
e.Graphics.DrawString(s, e.Style.Font.GdipFont, new SolidBrush(e.Style.TextColor), crect);
//Draw the image in a Grid.
e.Graphics.DrawImage(e.Style.ImageList.Images[0], irect);
e.Style.Text = s;
//to cancel the default drawing in a grid
e.Cancel = true;
}
}
The problem is the header text(with image) is a bit higher than the normal one. Please see the attached file.
Please help! Thanks!
i have a girdControl header with a image at right hand side in the header cell. I do as following:
if (e.RowIndex == 1 && e.ColIndex != 0)
{
e.Style.CellAppearance = GridCellAppearance.Raised;
if (e.ColIndex % 2 == 0)
{
string s = e.Style.Text;
e.Style.ImageList = ilDG;
e.Style.ImageIndex = 0;
e.Style.Text = " ";
//Draw the ColumnHeader cell in a Grid.
Rectangle crect = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Size.Width - e.Style.ImageList.ImageSize.Width, e.Bounds.Height));
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
//Draw the text in a Grid.
Rectangle irect = new Rectangle(new Point(e.Bounds.Right - e.Style.ImageList.ImageSize.Width, e.Bounds.Top + 2), e.Style.ImageList.ImageSize);
e.Graphics.DrawString(s, e.Style.Font.GdipFont, new SolidBrush(e.Style.TextColor), crect);
//Draw the image in a Grid.
e.Graphics.DrawImage(e.Style.ImageList.Images[0], irect);
e.Style.Text = s;
//to cancel the default drawing in a grid
e.Cancel = true;
}
}
The problem is the header text(with image) is a bit higher than the normal one. Please see the attached file.
Please help! Thanks!
DrawCellHeader.zip
SIGN IN To post a reply.
3 Replies
AD
Administrator
Syncfusion Team
September 22, 2006 05:03 AM UTC
Hi Lim,
Could you try this code to draw the image wtih text in a column header cell.
if (e.RowIndex == 1 && e.ColIndex != 0)
{
e.Style.CellAppearance = GridCellAppearance.Raised;
if (e.ColIndex % 2 == 0)
{
e.Style.ImageList = ilDG;
e.Style.ImageIndex = 0;
e.Style.TextMargins.Right = e.Style.ImageList.ImageSize.Width;
Rectangle crect = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Size.Width - e.Style.ImageList.ImageSize.Width, e.Bounds.Height));
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
//Draw the text in a Grid.
Rectangle irect = new Rectangle(new Point(e.Bounds.Right - e.Style.ImageList.ImageSize.Width, e.Bounds.Top + 2), e.Style.ImageList.ImageSize);
e.Graphics.DrawImage(e.Style.ImageList.Images[0], irect);
//to cancel the default drawing in a grid
e.Cancel = true;
}
}
Thanks,
Haneef
Could you try this code to draw the image wtih text in a column header cell.
if (e.RowIndex == 1 && e.ColIndex != 0)
{
e.Style.CellAppearance = GridCellAppearance.Raised;
if (e.ColIndex % 2 == 0)
{
e.Style.ImageList = ilDG;
e.Style.ImageIndex = 0;
e.Style.TextMargins.Right = e.Style.ImageList.ImageSize.Width;
Rectangle crect = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Size.Width - e.Style.ImageList.ImageSize.Width, e.Bounds.Height));
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
//Draw the text in a Grid.
Rectangle irect = new Rectangle(new Point(e.Bounds.Right - e.Style.ImageList.ImageSize.Width, e.Bounds.Top + 2), e.Style.ImageList.ImageSize);
e.Graphics.DrawImage(e.Style.ImageList.Images[0], irect);
//to cancel the default drawing in a grid
e.Cancel = true;
}
}
Thanks,
Haneef
AD
Administrator
Syncfusion Team
September 22, 2006 05:40 AM UTC
Thanks! Haneef!
AD
Administrator
Syncfusion Team
September 22, 2006 05:40 AM UTC
Thanks! Haneef!
SIGN IN To post a reply.
- 3 Replies
- 1 Participant
-
AD Administrator
- Sep 22, 2006 02:39 AM UTC
- Sep 22, 2006 05:40 AM UTC