What I mean is keep focus on the TextBox as in the applications focus property. I ended up creating a quick and dirty control to handle this for me. Just create a class and paste this code in, then you can reuse the control anywhere. Sorry no comments in code, feel free to clean up and add comments if you wish.
Option Strict Off
Public Class IntelisenseListBox
Inherits ListBox
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'Intelisense
'
Me.Visible = False
Me.ResumeLayout(False)
End Sub
Public Sub New()
Me.Visible = False
End Sub
Private WithEvents txtParentTextBox As RichTextBox
Public Property ParentTextBox() As RichTextBox
Get
Return txtParentTextBox
End Get
Set(ByVal Value As RichTextBox)
txtParentTextBox = Value
End Set
End Property
Private Sub txtParentTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtParentTextBox.KeyDown
If Me.Visible = True Then
Select Case e.KeyCode
Case Keys.Enter
e.Handled = True
End Select
End If
End Sub
Private Sub txtParentTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtParentTextBox.KeyPress
If e.KeyChar = CChar(".") Then
Dim curPoint As Point = txtParentTextBox.GetPositionFromCharIndex(txtParentTextBox.SelectionStart)
curPoint.Offset(txtParentTextBox.Left, txtParentTextBox.Top + txtParentTextBox.SelectionFont.Height)
Me.Location = curPoint
Me.Visible = True
ElseIf Me.Visible Then
If e.KeyChar = Convert.ToChar(Keys.Escape) Then
Me.Visible = False
ElseIf e.KeyChar = Convert.ToChar(Keys.Enter) Then
If Me.SelectedIndex > -1 Then
SendKeys.Send(Me.Text)
End If
Me.SelectedIndex = -1
Me.Visible = False
e.Handled = True
ElseIf e.KeyChar = Convert.ToChar(Keys.Space) Then
If Me.SelectedIndex > -1 Then
SendKeys.Send(Me.Text & " ")
End If
Me.SelectedIndex = -1
Me.Visible = False
e.Handled = True
End If
End If
End Sub
Private Sub IntelisenseListBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
txtParentTextBox.Focus()
End Sub
Private Sub txtParentTextBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtParentTextBox.KeyUp
If Me.Visible Then
If e.KeyCode = Keys.Up Then
Try
Me.SelectedIndex -= 1
Me.SelectedItem.EnsureVisible()
Catch
End Try
ElseIf e.KeyCode = Keys.Down Then
Try
Me.SelectedIndex += 1
Me.SelectedItem.EnsureVisible()
Catch
End Try
End If
End If
End Sub
End Class