Trackbar Background in a TabControl

Jon Tackabury picture Jon Tackabury · Mar 17, 2009 · Viewed 7.2k times · Source

I have a TrackBar control on a TabPage inside a TabControl. The background of the TrackBar is being drawn in grey while the TabPage is being drawn as white. There is no way to set the BackColor property of the TrackBar to transparent, and I can't override the drawing because there is no DrawMode property for the TrackBar. What options do I have to make the TrackBar fit in? Why doesn't it support visual styles?

Answer

Alex from Jitbit picture Alex from Jitbit · Apr 17, 2011

Simple

class MyTransparentTrackBar : TrackBar
{
    protected override void OnCreateControl()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        if (Parent != null)
            BackColor = Parent.BackColor;

        base.OnCreateControl();
    }
}

I also faced this (needed a transparent-background trackbar on a tab-control, that will work with both visualstyles enabled and disabled). And this worked for me.