Connell
Connell

Reputation: 14411

Drop down selection control

I have a nice little UserControl that is a draggable box with some text in. To the right hand side of the control is a little clickable arrow, which when clicked, I'd like to get a few options pop out of the right of the control.

I have already got a PopoutWindow class, which inherits ToolStripDropDown, which allows me to pop up get a new control to 'pop out' of the right hand side of this arrow with the following usage.

  MyPopoutWindow options = new MyPopoutWindow ();
  PopoutWindow popout = new PopoutWindow(options);
  popout.Show(arrowButton, arrowButton.Width, 0);

MyPopoutWindow is (currently) a custom UserControl, which I want to be the same as the popped-out body of a ComboBox, or a ToolStripMenu.

Does anyone know of a Winforms control I can use or inherit to get this effect? I've tried using ToolStripDropDownMenu and ToolStripDropDown but I get the following Exception:

Top-level control cannot be added to a control.

Thanks,

Upvotes: 1

Views: 355

Answers (1)

Connell
Connell

Reputation: 14411

The solution was actually quite obvious (isn't it always!). As I mentioned in the question, I'd tried using a ToolStripDropDown but that threw an Exception.

To solve this, I've got MyPopoutWindow to inherit ToolStripDropDown, but in the constructor, set the TopLevel property to false. This worked!

public MyPopoutWindow()
{
    TopLevel = false;
}

Upvotes: 1

Related Questions