In my previous entry, "Using ToolStripControlHost with a Trackbar", I noted that the problem with this method resulted in the ToolStripTrackBar looking unlike anything else on the ToolStrip when it was in ManagerRenderMode. This has driven me nuts during the preceding week. Here are some of the steps that I took to solve this problem, all of which failed:
Tried to set Backcolor on ToolStripTrackBar: no effect.
Override OnPaint method with ToolStripTrackBar: no effect.
Derive MyTrackBar from TrackBar, override OnPaintBackground, put MyTrackBar in ToolStripControlHost: color, but no trackbar!
The latter step failed because TrackBar is one of those .NET controls that wants to perform all the drawing--if you override OnPaint, it won't be called unless you call SetStyle, as Tom Holt described in this CodeProject article:
// this call says "I'll draw it myself" this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
From what I read on various message boards, no one had my specific problem (needing a TrackBar on a ToolStrip), but plenty of people had a situation where they wanted the TrackBar to be transparent on a Form that contained a bitmap image or specific visual style. I could see that type of TrackBar being useful and potentially the key to solving this problem, and I found a great article from Bob Powell showing how to create a transparent C# control. After finding this MSDN article with sample code for the TrackBarRenderer class, I decided to create my own control: CrystalTrackBar.

CrystalTrackBar has two different modes you can set. One is "TransparencyMode", which allows the background of the Form to show through, as it does with the second control in this screenshot. I then proceeded to take the CrystalTrackBar, and wrap it in a ToolStripControlHost to create CrystalToolStripTrackBar. The transparency mode allows the finely rendered background of the ToolStrip to show through, creating a seemless effect. As a bonus, I created a second mode that works when TransparencyMode is set to false--a gradient effect is created, as in the first control within the form. You can set Color1, Color2, and the angle of the gradient.
I'll be sharing the code soon. CrystalTrackBar isn't yet as feature rich as the TrackBar and I want to include some additional modes. I've got a small painting bug when I move the thumb around, but I may release it in the hopes that someone will suggest a better way of doing things.

Comments (2)
Richard,
this is the next best thing after warm water! Could you please send CrystalTrackBar or put it up here as I would eagerly use it.
Please send me an e-mail if there's any update.
Thanks,
Gabor
Posted by Gabor Ratky | November 3, 2006 7:47 AM
Posted on November 3, 2006 07:47
I can put up what I have currently working, although it has a update bug and it needs more work to be as feature-rich as the .NET Trackbar control.
Posted by Richard Guion | November 3, 2006 10:23 AM
Posted on November 3, 2006 10:23