Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How repaint the color of ColumnHead in ListView?

How repaint the color of ColumnHead in ListView?

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fu0
    wrote on last edited by
    #1

    i want to write my own listview control that i can repaint the columnhead's color. but i dont know how to do it. i use Graphics.FillRectangle() in the OnPaint() method but did not get the correct result.

    H 1 Reply Last reply
    0
    • F fu0

      i want to write my own listview control that i can repaint the columnhead's color. but i dont know how to do it. i use Graphics.FillRectangle() in the OnPaint() method but did not get the correct result.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      The ListView class encapsulates the List-View common control. Sticking to pure managed code won't accomplish what you need. You must extend the ListView control, override WndProc, and handle windows messages like you would in VC++. There are plenty of articles here on CodeProject about this, and you should familiarize yourself with the windows messages and common controls by reading Windows Controls[^]. For one example, see a previous post about defining an event to fire when column widths change: http://www.codeproject.com/script/comments/forums.asp?msg=807702&forumid=1649#xx807702xx[^]. Another good article about handling notification messages for the List-View common control (because that's really what this all comes down to) is http://www.codeproject.com/cs/miscctrl/listviewfilter.asp[^]. In your case, since you're paining, you'll need to handle the NM_CUSTOMDRAW message (for a list-view). This will, once you've handle the right sequence of windows messages, give you an HDC (handle to a device context). You can get a Graphics object from this by using Graphics.FromHdc, but simply overriding the OnPaint method (or handlig the Paint event, which is much slower and a bad idea when done in a derived control) will not work. You must draw to the DC that the list-view is using for the list-view column header.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups