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.
Syncfusion Feedback

Draw Image in header

Thread ID:

Created:

Updated:

Platform:

Replies:

49617 Sep 22,2006 02:39 AM UTC Sep 22,2006 05:40 AM UTC Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 22, 2006 02:39 AM UTC

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!

DrawCellHeader.zip

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On September 22, 2006 05:40 AM UTC

Thanks! Haneef!

Administrator [Syncfusion]
Replied On September 22, 2006 05:40 AM UTC

Thanks! Haneef!

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.

Warning Icon 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.Close Icon

;