Question

I was wondering if there is a way to setup a level indicator inside the track of the .NET TrackBar?

My usage scenario is this. I need an audio squelch control. So I want to use a TrackBar where the user drags between 0 and 100 squelch. But at the same time I want to show the current audio level in the track of the TrackBar. So that the user knows where the current audio level is relation to the squelch.

Any suggestions? Is this something were I need to override the paint method of the TrackBar? Or is there a free control somewhere I could use?

Was it helpful?

Solution

This will not be as easy as it might seem. One cannot simply augment the appearance of the TrackBar control. You have to trigger UserPaint by adding the following line to the constructor of a class that derives from TrackBar:

SetStyle(ControlStyles.UserPaint, true);

This will, however, force you to own all of the painting. Meaning that you will then need to override both OnPaint and OnPaintBackground and use the methods in TrackBarRenderer to paint the entire control.

Having said that, the methods given to you are pretty straightforward, and drawing the control is relatively easy.

Note: this Code Project article is bound to have lots of good pointers if you decide to pursue full-on custom drawing. Perhaps could even serve as your replacement control.

There are others. Just do a Google search for "C# TrackBar custom draw".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top