Click to See Complete Forum and Search --> : [RESOLVED] [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look-and-feel


dee-u
March 4th, 2009, 02:17 AM
Anyone who could provide me a direction to start with? Any other look that is not dull is also very much welcome!

dee-u
March 4th, 2009, 03:03 AM
This is my effort. I am failing to fill the entire ColumnHeader with my gradient, why so?

private Bitmap GetVerticalGradient()
{
Bitmap Gradient = new Bitmap(1, 2);
Gradient.SetPixel(0, 0, ProfessionalColors.ToolStripGradientBegin);
Gradient.SetPixel(0, 1, ProfessionalColors.ToolStripGradientEnd);
return Gradient;
}

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
//e.Graphics.DrawImage(GetVerticalGradient(), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); //then we draw an outline
e.Graphics.DrawImage(GetVerticalGradient(), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), new Rectangle(0, 0, GetVerticalGradient().Width,GetVerticalGradient().Height), GraphicsUnit.Pixel);
e.Graphics.DrawString(e.Header.Text, new Font("tahoma", 8), new SolidBrush(Color.Black), e.Bounds);
}

dglienna
March 4th, 2009, 09:57 PM
How about this?


Public Class thisRenderer
Inherits System.Windows.Forms.ToolStripRenderer
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As ToolStripRenderEventArgs)
MyBase.OnRenderToolStripBackground(e)
Dim b As New Drawing2D.LinearGradientBrush(e.AffectedBounds, Color.WhiteSmoke, e.BackColor, _
Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(b, e.AffectedBounds)
End Sub
End Class

' this could be called in a form like this:
' ToolStrip1.Renderer = New myRenderer

dee-u
March 4th, 2009, 11:47 PM
Thanks! With your suggestion I came up with this which was better than my previous implementation. The problem now is that it is no longer catching mousehover and mousedown.

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ProfessionalColors.ToolStripGradientBegin, ProfessionalColors.ToolStripGradientEnd, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.Graphics.DrawLine(Pens.LightSkyBlue, e.Bounds.Right - 2, e.Bounds.Top, e.Bounds.Right - 2, e.Bounds.Bottom);
e.Graphics.DrawString(e.Header.Text, new Font("tahoma", 9), new SolidBrush(Color.Black), e.Bounds);
}

Sorry, got to spread first. =(

dglienna
March 5th, 2009, 12:34 AM
Didn't see any mention of that in your last post!