Changing color of scroll bar in ListView in WinForms

17,166

The short answer: No, it's not possible.

The longer (and more accurate) answer:
Unfortunately, this is nowhere near as simple as setting a property. The reason is that the scroll bars used by the ListView control are not actual scroll bar controls. They don't have their own window handles, and their drawing is managed completely internally by the ListView control. And, of course, the ListView control in WinForms is just a thin wrapper around that same control provided by the Win32 API. Neither of them expose any facility for changing the scroll bar's color.

But the plot thickens. I said that the ListView control (note that this also applies to the TreeView) handles drawing the scroll bars itself, which should indicate that you can't simply handle its Paint event and draw them yourself like you can with many of the other WinForms controls. The Paint event corresponds to the window message WM_PAINT, but there is another message (WM_NCPAINT) that is sent to a window when it's non-client area needs to be painted. It stands to reason that the scrollbars are painted when the WM_NCPAINT message is received, because I've said they are part of the ListView control's frame. But they're not.

Then there's the issue of pointlessly excessive customization. I'm a strong advocate for applications that respect the user's current theme settings. If I have Windows configured to use a high contrast theme (or if I just can't stand the color blue, so I have a green theme instead), I expect the applications on my computer to draw their UI elements using that theme. Whatever you design your scroll bar to look like, however awesome it looks on your computer, it's guaranteed to look like garbage on someone's computer. If that someone is one of your users, oops. The handful of applications that use custom themes do a lot of testing and that still doesn't keep them from experiencing problems.

You might be able to hook the scroll bars themselves somehow, but that's more than likely out of the question, as they are implemented partially in kernel mode. In fact, I've heard that the authors of WindowBlinds claimed hooking scroll bars was the most difficult thing they had to do. And they're certainly not sharing any of their tricks.

The only thing that really seems hopeful is James Brown's Custom Scrollbar Library, but it's written in C. You're on your own porting that to C#. And as usual with this kind of thing, it's not going to be without it's problems. Reading the comments shows quite a few people with various issues. If you don't know the Win32 API pretty well, you're probably not going to be able to fix any bugs this potentially introduces into your application.

There's a reason a Google search on this subject almost exclusively uncovers unanswered questions. For what it's worth, this is way easier in WPF.

Share:
17,166
Sreekumar P
Author by

Sreekumar P

Over the past 9 years, I am working in the field of Software Development. Using technologies Angular5, AngularJS, npm, TypeScript, SASS, ngrx (redux), Nodejs, WebSockets, Figma(UX), RxJS, HTML5, jQuery, RequireJS, Grunt, Bower, Git, Github, LESS, CSS3, Electron, ASP.net, C#.net, WCF, MVC, SQL Server 2016. Have experience in Team handling and Customer (USA) direct communications. LinkedIn Profile: https://www.linkedin.com/in/sreepk/

Updated on June 14, 2022

Comments

  • Sreekumar P
    Sreekumar P almost 2 years

    In a Windows Forms application, is it possible to change the color of a scrollbar in for the ListView control?

    Please let me know what property or code I need for achieving this, I could not find and also was not able to develop anything like that.

    My intention is to apply a theme to my whole WinForms application.

  • Hesein Burg
    Hesein Burg about 7 years
    Cody Gray says it's not possible, it must not be possible.
  • Roni Tovi
    Roni Tovi over 3 years
    As a computer programmer and after 19 years of field experience, I totally agree to the part that a developer should respect the user's own preferences, even for the core functionalties of your application, along with the theming options. However Windows (even 10) comes with a very solid and (arguably) ugly (at least non-modern) theme and a very little percantage of users change (even know how to change) them. So I guess the best workaround would be giving a chance to your users when they want to change them. I did it for my listview column headers but now I'm suffering about the scroll bar...