I'm currently developing an application that displays images (bmp, jpg, etc) in a Windows Forms application. The application can scale the image within a panel, making it fit, or allowing an interactive scale. To enhance this functionality, I wanted to include a slider Trackbar control to my toolstrip. The end result needed to look like this:
Fortunately, this is easily accomplished with .NET 2.0, by using the ToolStripControlHost class to wrap controls for the ToolStrip. I was even able to find code that specifically added the Trackbar on WindowsForms.net. All I had to do was place this code inside a file called ToolStripTrackBar.cs (see the link to this below), add a few using clauses to bring in the required assemblies, and it compiled just fine. Now what? I spent a good period of time just trying to find TrackBar in the Visual Studio Toolbox. At first I thought it might show up where the user controls are located, under the first control group with the name of your program. Nothing new there. Nada for the "All Windows Forms" control group. I couldn't find it anywhere. Compiled again, exited and restarted Visual Studio. Nada. I decided to give up and decided to add some buttons to my toolstrip. Voila! On the bottom of the menu that allows you to add toolstrip items, the Trackbar item had wonderfully appeared!
It's all very easy and automatic, however none of the references to this specific example told me where to find the Trackbar. The benefits of having the Trackbar in Visual Studio designer are great, as you can visually position and resize the control. However, the Properties settings for the trackbar object, embedded in the ToolStripControlHost, were not persistent. I had to write a method to intialize the trackbar object:
private void InitTrackBar() { zoomToolStripTrackBar.TrackBar.TickStyle = TickStyle.None; zoomToolStripTrackBar.TrackBar.BackColor = this.toolStrip1.BackColor; zoomToolStripTrackBar.TrackBar.Scroll += new EventHandler(this.scrollZoom_Scroll); zoomToolStripTrackBar.TrackBar.Value = 5; }
That was problem #1. Problem #2 was that while the ToolStrip was set to ManagerRenderMode, this property does not automatically extend to the ToolStripControlHost. If you look at my first picture, you'll notice that the TrackBar is grey while the rest of the ToolStrip is blue. If I figure out the reason for this, I'll record it here.
Link:
ToolStripTrackBar.cs


Comments (3)
This is exactly what I am looking for! I am new at this. Where do you put the ToolStripTrackBar.cs file?
Posted by Jim | September 17, 2006 2:08 PM
Posted on September 17, 2006 14:08
Nevermind. I figured it out!
Project > Add Existing Item
Then build (or debug) once does the trick.
Thanks again for the lead.
Posted by Jim | September 17, 2006 4:14 PM
Posted on September 17, 2006 16:14
It's now available in the Crystal Toolkit. For the latest version, get it on the Downloads page:
http://www.attilan.com/downloads/
Posted by Richard Guion | November 26, 2006 7:39 PM
Posted on November 26, 2006 19:39