在Popoup中显示UserControl

时间:2016-08-17 11:47:56

标签: .net vb.net winforms

我有一个按钮,另一个控件放在usercontrol中 当点击usercontrol中的bitton时,我想将按钮下方的控件弹出到所有其他控件的topp enter image description here

1 个答案:

答案 0 :(得分:4)

您可以在ToolStripControlHost中托管任何类型的Control,然后将其添加到ToolStripDropDown的项目中,然后显示下拉列表:

Dim dropdown As ToolStripDropDown = New ToolStripDropDown()
Dim c As UserControl1 = New UserControl1()
Dim host As ToolStripControlHost = New ToolStripControlHost(c)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button2.Click
    If (dropdown.Items.Count = 0) Then
        host.BackColor = Color.White
        host.Margin = New Padding(2)
        c.MinimumSize = New Size(120, 100)
        dropdown.Padding = New Padding(0)
        dropdown.Margin = New Padding(0)
        dropdown.Items.Add(host)
    End If
    dropdown.Show(Button2, 0, Button1.Height)
End Sub

DropDown