1

I am creating a application in c# and I would like to get the same effect on a trackbar component, like in the system volume application in windows 7 (the green line which represents the current sound level output).

I'd like to draw a green line behind the trackbar depending on some logic. The problem is that the trackbar has a background color, and if i draw anything behind it, the background color will paint over the line, and I can't draw over it because it will paint over the trackbar slider/button .

Do I have to implement my own trackbar paint method from scratch or is there any simpler solution?

Matt Tester
  • 4,663
  • 4
  • 29
  • 32
blejzz
  • 3,349
  • 4
  • 39
  • 60

1 Answers1

1

I had a similar issue and unfortunately you can't do this on the trackbar control. However it is quite straight forward to create your own user drawn trackbar have a look at this article.

However, what I ended up doing was using the TrackBarRenderer class to create my own trackbar, the advantage of this is that it uses the same code, therefore has the same style as the standard trackbar, but you can change almost everything about it, there is an example of how to create a trackbar using this style here.

If you look through the code you should see that all you need to do is change the OnPaint method to paint over the trackRectangle with a colour of your choosing.

Reznoir
  • 909
  • 1
  • 11
  • 27