i know a Windows Combobox
control is nothing but a Textbox
and a ListBox
glued together.
i need to simulate the same thing in WinForms. i am trying to figure out Windows window options that must be set to achieve the proper effect.
- the drop-down cannot be a child window - otherwise it is clipped to the parent's area
- conceptually it must be a pop-up window - an overlapped window
- it can be an owned window - An owned window is always above its owner in the z-order. The system automatically destroys an owned window when its owner is destroyed. An owned window is hidden when its owner is minimized.
The best i've managed so far is to create
- a borderless (
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
)
- topmost (
this.TopMost = true
)
- form that doesn't show in the taskbar (
this.ShowInTaskbar = false
)
this borderless topmost form contains my "drop-down" control. i "hide" my dropdown when the dropdown form loses focus:
this.Deactivate += new EventHandler(TheDropDownForm_Deactivate);
void TheDropDownForm_Deactivate(object sender, EventArgs e)
{
...
this.Close();
}
This conglomeration of mess works well enough...
...except that "drop-down" takes focus away from the owner form.
And this is my question, what properties should my popup window have?
But then how do i hide my drop-down form when it loses focus - when it cannot lose focus?
How do i simulate a combo-box drop-down in .NET?
Note: Don't confuse what you see in the example screenshot with something else. i am asking how to create "drop-down" form in Winforms - the contents can be different than the screenshot above:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…