Intellisense within a richtextbox

spebola

Well-known member
Joined
Mar 9, 2003
Messages
50
Location
Oklahoma City
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.
 
I found this code on the internet looking for a solution like the one youre looking for... I never used it cause at the end we used another kind of solution for the app, but this might give you a good start and you can modify it and complete it

Regards
 
Thanks iebidan for the response. I did review the code and got a few ideas.

I have solved the location problem. All location points are to the point of reference of the container, in this case the form. By calculating the containing rectangle of the form I can ensure the list box is in an appropriate place.

Any ideas on auto scrolling in the listbox (similar to IDE intellisense) would be appreciated. For example .s scrolls to properties and methods beginning with "s" in IDE intellisense.

Thanks again iebidan.
 
Sounds like a KeyDown event to me. Autoscrolling I mean. Capture a KeyDown for the listbox and use a loop to read the first letter of every Item. If you dont know how to use the KeyDown event, here is some code:
C#:
void BrowserLB_KeyDown(object sender, KeyEventArgs e)
{
	if(e.KeyValue==(int)Keys.s)
        {
              this.BrowserLB.SetSelected(25, true);
        }
}
I didnt use a loop but you get the idea.
 
Back
Top