2

this might be a very global question but here we go:

I was wondering how I could make a trackbar like Virtualbox. They have a trackbar that have custom colors at the bottom to show if you've assigned too much RAM to your virtual system.
Now my question is: How can I give my trackbar custom colors?
I have read something about e.graphics etc. and overriding other functions, but I can't seem to find any information about this ):.

If you know what I mean and have sources to good tutorials and/or examples that would be awesome! Because I really don't know where to look anymore :(.

I am programming in C#, WinForms.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Yuki Kutsuya
  • 3,968
  • 11
  • 46
  • 63
  • You can use the TrackBarRenderer functionality, like [here](https://stackoverflow.com/questions/3484143/visual-styles-independent-drawing) and [here](https://msdn.microsoft.com/en-us/library/system.windows.forms.trackbarrenderer(v=vs.110).aspx) – rupweb May 22 '18 at 10:14

1 Answers1

2

As Hans mentioned the standard trackbar is pretty limiting. You can change the background color through TrackBar.BackColor property. Otherwise you will have to create a custom control and override the OnPaint method:

partial class MyTrackBar : System.Windows.Forms.TrackBar
{       
    protected override void  OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.FillRectangle([Brush color], ClientRectangle);
    }
}

Third option is to use a trackbar already created. Like free CodeProject trackbar or commercial Devexpress one.

Community
  • 1
  • 1
Raj Ranjhan
  • 3,869
  • 2
  • 19
  • 29