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 best i've managed so far is to create
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
)this.TopMost = true
)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:
Step 2: Drag the ComboBox control from the ToolBox and drop it on the windows form. You are allowed to place a ComboBox control anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the ComboBox control to set the DropDownStyle property of the ComboBox.
Win Form has been used to develop many applications. Because of its high age (born in 2003), WinForm was officially declared dead by Microsoft in 2014. However, Win Form is still alive and well.
WPF, would be your answer to Windows Forms if you are on the . NET platform.
Using a ToolStripControlHost
and a ToolStripDropDown
can achieve the same effect.
From this answer:
Private Sub ShowControl(ByVal fromControl As Control, ByVal whichControl As Control)
'\\ whichControl needs MinimumSize set:'
whichControl.MinimumSize = whichControl.Size
Dim toolDrop As New ToolStripDropDown()
Dim toolHost As New ToolStripControlHost(whichControl)
toolHost.Margin = New Padding(0)
toolDrop.Padding = New Padding(0)
toolDrop.Items.Add(toolHost)
toolDrop.Show(Me, New Point(fromControl.Left, fromControl.Bottom))
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With