dotnetmonitor.com |
|
||||||||||||
| This is the base class for our ToolStripTextBox,
ToolStripComboBox, ToolStripProgressBar, and can wrap any user control to be hosted
in the ToolStrip. There are multiple ways to use ToolStripControlHost:: Inherit
from ToolStripControlHost or use ToolStripControlHost directly.
toolStrip1.Items.Add(new ToolStripControlHost(new TrackBar())); Sample showing a user control in a dropdown -private void button1_Click(object sender, EventArgs e) { ToolStripDropDown toolStripDropDown = new ToolStripDropDown(); // Create some user control UserControl1 uc = new UserControl1(); uc.Margin = Padding.Empty; toolStripDropDown.SuspendLayout();
// create the control host to host the user control - make sure it has no margin ToolStripControlHost host = new ToolStripControlHost(uc); host.Margin = Padding.Empty;
// add the control host to the toolstripdropdown toolStripDropDown.Items.Add(host);
// set the padding of the toolstripdropdown to be empty toolStripDropDown.Padding = Padding.Empty;
// show no borders toolStripDropDown.Renderer = new BorderlessRenderer();
toolStripDropDown.ResumeLayout();
toolStripDropDown.Show(this.button1, 10, 10);
} private class BorderlessRenderer : ToolStripProfessionalRenderer { protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { // do nothing }
} Creating a wrapper for your ToolStripControlHost The following sample shows how to wrap a TrackBar by inheriting from ToolStripControlHost. It is possible to just host the trackbar by these four lines of code:
TrackBar t = new TrackBar();
However, if you want to use the TrackBar in the designer, you'll have to create a wrapper around the ToolStripControlHost class. The following sample shows how to wrap a property (TrackBar.Value), and an event (TrackBar.ValueChanged).
[System.ComponentModel.DesignerCategory("code")] /// <summary> /// <summary> // Add other initialization code here. [DefaultValue(0)]
/// <summary> }
// add an event that is subscribable from the designer.
|
||||||||||||
|
||||||||||||