Public Class MySearchBoxNew
Dim PopUpControl As ToolStripDropDown
Dim List_Box As ListBox
Dim Control_Host As ToolStripControlHost
Private Sub MySearchBoxNew_Enter(sender As Object, e As System.EventArgs) Handles Me.Enter
PopUpControl = New ToolStripDropDown
List_Box = New ListBox
Control_Host = New ToolStripControlHost(List_Box)
List_Box.BorderStyle = BorderStyle.None
List_Box.SelectionMode = SelectionMode.One
List_Box.BindingContext = New BindingContext
List_Box.IntegralHeight = True
List_Box.Items.Clear()
List_Box.Items.Add("A")
List_Box.Items.Add("B")
List_Box.Items.Add("c")
List_Box.Items.Add("D")
Control_Host.Padding = New Padding(0)
Control_Host.Margin = New Padding(0)
Control_Host.AutoSize = False
PopUpControl.Padding = New Padding(0)
PopUpControl.Margin = New Padding(0)
PopUpControl.Width = Me.TextBox1.Width
PopUpControl.AutoSize = True
PopUpControl.AutoClose = False ' **** **** **** ****
PopUpControl.Items.Add(Control_Host)
End Sub
Private Sub MySearchBoxNew_Leave(sender As Object, e As System.EventArgs) Handles Me.Leave
Me.DiscardControls()
End Sub
Private Sub MySearchBoxNew_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus
Me.DiscardControls()
End Sub
Private Sub ShowDropDown()
Dim pnt As Point = New Point(Me.TextBox1.Location.X, Me.TextBox1.Location.Y + Me.TextBox1.Height)
Dim PointToShowMenu As Point = Me.PointToScreen(pnt)
If PopUpControl Is Nothing Then PopUpControl = New ToolStripDropDown
If List_Box Is Nothing Then List_Box = New ListBox
If Control_Host Is Nothing Then Control_Host = New ToolStripControlHost(List_Box)
PopUpControl.Show(PointToShowMenu)
End Sub
Private Sub CloseDropDown()
PopUpControl.Hide()
End Sub
Private Sub DiscardControls()
If PopUpControl.Visible Then PopUpControl.Close()
If PopUpControl IsNot Nothing Then PopUpControl.Close()
Control_Host = Nothing
PopUpControl = Nothing
List_Box = Nothing
End Sub
End Class