I want to show ToolStripDropDown
in a way as ComboBox
s dropdown is shown (or for example DateTimePicker
s dropdown). So I wrote this code in my Form
:
private readonly ToolStripDropDown _toolStripDropDown = new ToolStripDropDown
{
TopLevel = false,
CanOverflow = true,
AutoClose = true,
DropShadowEnabled = true
};
public Form1()
{
InitializeComponent();
var label = new Label{Text = "Ups"};
var host = new ToolStripControlHost(label)
{
Margin = Padding.Empty,
Padding = Padding.Empty,
AutoSize = false,
Size = label.Size
};
_toolStripDropDown.Size = label.Size;
_toolStripDropDown.Items.Add(host);
Controls.Add(_toolStripDropDown);
}
private void button1_Click(object sender, EventArgs e)
{
_toolStripDropDown.Show(button1.Left, button1.Top + button1.Height);
}
When I click on button my ToolStripDropDown
is shown but there is no shadow, no overflow, no autoclose. What am I doing wrong?
Label
in ToolStripControlHost
is for simplicity. I use WinForms and .NET 4.
Update:
As you can see dropdown "Ups" doesn't overflow window, doesn't has shadow (ComboBox
s dropdown has both) and even when I clicked on ComboBox
dropdown "Ups" is still visible.