spebola
Well-known member
I am trying to use a listbox (should operate similar to the IDE Intellisense) within a richtextbox. The problem I am having is the location of the listbox and positioning of the list as the user keys characters. The following is the code Im using:
Public WithEvents lstInsert As New ListBox()
Private Sub Par_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstInsert.Name = "lstInsert"
lstInsert.Visible = False
Dim sizept As New Size()
sizept.Height = 136
sizept.Width = 180
lstInsert.Size = sizept
lstInsert.Items.Clear()
Fill listbox from database (code omitted)
Me.Controls.Add(lstInsert)
lstInsert.Location = New Point(0, 0)
lstInsert.BackColor = Color.LightGoldenrodYellow
lstInsert.BorderStyle = BorderStyle.FixedSingle
lstInsert.SendToBack()
End Sub
Private Sub rtbPar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rtbPar.KeyPress
If KeyAscii(e) = 60 Then
Dim pt As New Point()
pt = rtbPar.PointToScreen _
( rtbPar.GetPositionFromCharIndex(rtbPar.TextLength))
lstInsert.Visible = True
lstInsert.Location = pt
lstInsert.BringToFront()
Else
lstInsert.Visible = False
End If
End Sub
Private Sub lstInsert_SelectedValueChanged(ByVal sender As _
Object, ByVal e As System.EventArgs) Handles _
lstInsert.SelectedValueChanged
rtbPar.SelectedText = CType(lstInsert.SelectedItem, String) _
& ">"
lstInsert.Visible = False
End Sub
How can I code this to ensure that the listbox will always be within the form? What code needs to be added to scroll the listbox as the user enters characters? If the user enters a "C", I want to auto scroll to entries starting with a "C".
When the user enters a less than sign "<", the listbox appears, and can select the approriate entry. FYI, the data in the richtextbox is a "canned paragraph" that will be used in a formal contract, and the info between "<" and ">" will be used to insert data from the database. Example: <Customer Name>
Any suggestions will be appreciated.
Public WithEvents lstInsert As New ListBox()
Private Sub Par_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstInsert.Name = "lstInsert"
lstInsert.Visible = False
Dim sizept As New Size()
sizept.Height = 136
sizept.Width = 180
lstInsert.Size = sizept
lstInsert.Items.Clear()
Fill listbox from database (code omitted)
Me.Controls.Add(lstInsert)
lstInsert.Location = New Point(0, 0)
lstInsert.BackColor = Color.LightGoldenrodYellow
lstInsert.BorderStyle = BorderStyle.FixedSingle
lstInsert.SendToBack()
End Sub
Private Sub rtbPar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rtbPar.KeyPress
If KeyAscii(e) = 60 Then
Dim pt As New Point()
pt = rtbPar.PointToScreen _
( rtbPar.GetPositionFromCharIndex(rtbPar.TextLength))
lstInsert.Visible = True
lstInsert.Location = pt
lstInsert.BringToFront()
Else
lstInsert.Visible = False
End If
End Sub
Private Sub lstInsert_SelectedValueChanged(ByVal sender As _
Object, ByVal e As System.EventArgs) Handles _
lstInsert.SelectedValueChanged
rtbPar.SelectedText = CType(lstInsert.SelectedItem, String) _
& ">"
lstInsert.Visible = False
End Sub
How can I code this to ensure that the listbox will always be within the form? What code needs to be added to scroll the listbox as the user enters characters? If the user enters a "C", I want to auto scroll to entries starting with a "C".
When the user enters a less than sign "<", the listbox appears, and can select the approriate entry. FYI, the data in the richtextbox is a "canned paragraph" that will be used in a formal contract, and the info between "<" and ">" will be used to insert data from the database. Example: <Customer Name>
Any suggestions will be appreciated.