2

I want to show ToolStripDropDown in a way as ComboBoxs dropdown is shown (or for example DateTimePickers 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:
issue image

As you can see dropdown "Ups" doesn't overflow window, doesn't has shadow (ComboBoxs dropdown has both) and even when I clicked on ComboBox dropdown "Ups" is still visible.

Artholl
  • 1,291
  • 1
  • 19
  • 38
  • 1
    Your question is somewhat unclear. Can you explain more about, what do you mean by: `but there is no shadow, no overflow, no autoclose. What am I doing wrong?` Update the question if required. – Nagaraj Tantri Feb 11 '14 at 10:54
  • Thank you for reply. I updated my question and hope it is more understandable now. – Artholl Feb 11 '14 at 11:31

1 Answers1

6

You are parenting your control to the Form, which restricts it to that parent's ClipRectangle.

Remove the TopLevel designation, remove the parenting, calculate the position in screen coordinates, and finally, show the menu:

    private readonly ToolStripDropDown _toolStripDropDown = new ToolStripDropDown
    {
        //TopLevel = false,
        CanOverflow = true,
        AutoClose = true,
        DropShadowEnabled = true
    };

    public Form4()
    {
        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)
    {
        Point pt = this.PointToScreen(button1.Location);
        pt.Offset(0, button1.Height);
        _toolStripDropDown.Show(pt);

    }
DonBoitnott
  • 10,787
  • 6
  • 49
  • 68