[英]How to simulate a drop-down window in WinForms?
i know a Windows Combobox
control is nothing but a Textbox
and a ListBox
glued together . 我知道Windows
Combobox
控件只是一个Textbox
和一个ListBox
粘在一起 。
i need to simulate the same thing in WinForms. 我需要在WinForms中模拟相同的东西。 i am trying to figure out Windows window options that must be set to achieve the proper effect.
我试图找出必须设置以实现正确效果的Windows窗口选项。
The best i've managed so far is to create 到目前为止我所管理的最好的是创造
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
) this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
) this.TopMost = true
) this.TopMost = true
) this.ShowInTaskbar = false
) 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? 我如何模拟.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:
我问如何在Winforms中创建“下拉”表单 - 内容可能与上面的截图不同:
Using a ToolStripControlHost
and a ToolStripDropDown
can achieve the same effect. 使用
ToolStripControlHost
和ToolStripDropDown
可以实现相同的效果。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.