CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    304

    [RESOLVED] [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look-and-feel

    Anyone who could provide me a direction to start with? Any other look that is not dull is also very much welcome!

  2. #2
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    304

    Re: [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look-and-feel

    This is my effort. I am failing to fill the entire ColumnHeader with my gradient, why so?

    Code:
    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);
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look-and-feel

    How about this?


    Code:
    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    304

    Re: [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look-and-feel

    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.
    Code:
    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. =(

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [RESOLVED] [2005]OwnerDrawing the Listview ColumnHeaders to 2003/2007 Office look

    Didn't see any mention of that in your last post!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured