using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design; [System.ComponentModel.DesignerCategory("code")] [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)] public partial class ToolStripTrackBar : ToolStripControlHost { public ToolStripTrackBar() : base(CreateControlInstance()) { } /// /// Create a strongly typed property called TrackBar - handy to prevent casting everywhere. /// public TrackBar TrackBar { get { return Control as TrackBar; } } /// /// Create the actual control, note this is static so it can be called from the /// constructor. /// /// /// private static Control CreateControlInstance() { TrackBar t = new TrackBar(); t.AutoSize = false; t.Height = 16; // Add other initialization code here. return t; } [DefaultValue(0)] public int Value { get { return TrackBar.Value; } set { TrackBar.Value = value; } } /// /// Attach to events we want to re-wrap /// /// protected override void OnSubscribeControlEvents(Control control) { base.OnSubscribeControlEvents(control); TrackBar trackBar = control as TrackBar; trackBar.ValueChanged += new EventHandler(trackBar_ValueChanged); } /// /// Detach from events. /// /// protected override void OnUnsubscribeControlEvents(Control control) { base.OnUnsubscribeControlEvents(control); TrackBar trackBar = control as TrackBar; trackBar.ValueChanged -= new EventHandler(trackBar_ValueChanged); } /// /// Routing for event /// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged /// /// /// void trackBar_ValueChanged(object sender, EventArgs e) { // when the trackbar value changes, fire an event. if (this.ValueChanged != null) { ValueChanged(sender, e); } } // add an event that is subscribable from the designer. public event EventHandler ValueChanged; // set other defaults that are interesting protected override Size DefaultSize { get { return new Size(200, 16); } } }