Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a form at cursor location in a textbox 4

Status
Not open for further replies.

ZmrAbdulla

Technical User
Joined
Apr 22, 2003
Messages
4,364
Location
AE
Is that possible to open small form at the current cursor location of a multiline=true textbox?
I am trying to imitate the intelliscence of the vb code window.
It was possible with vb6 API calls. No idea how with .net.

Thanks

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
ca8msm, I think we posted at almost the same time. I like problems like this.

I also like your variation. I didn't think of a "floating" ListBox. Zameer said a new form and I focussed only on that - but I do think your listbox is neater than mine.

[vampire][bat]
 
I think you guys should work more and play less. But stars allround.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Chrissie, you're absolutly right - it's far too late here to be playing around with this...but I liked the idea and thought it might turn out to be useful!

E&F - Yeah, guess we posted at the same time. You've just posted the next step that I was gonna look at (appending the text back to the RTB) so that's something else for me to look at! It's useful to see all the different ways of approaching this problem - hopefully we'll come out with an nice Intellisense class/control at the end of this!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, one small step closer (by the way, thanks for OemPeriod, I couldn't find the full stop which is why I just used Decimal)

Code:
  'Using form2 for listbox
  'Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

  '  If e.KeyCode = Keys.Decimal Then
  '    Dim f2 As New Form2(RichTextBox1)
  '    Dim pt As New Point
  '    pt = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
  '    pt.X += RichTextBox1.Location.X + Me.Location.X + 5
  '    pt.Y += RichTextBox1.Location.Y + Me.Location.Y + 21 + 5
  '    f2.FormBorderStyle = FormBorderStyle.SizableToolWindow
  '    f2.Opacity = 0.4
  '    f2.StartPosition = FormStartPosition.Manual
  '    f2.Location = pt
  '    f2.Show()
  '  End If

  'End Sub

  'Using "floating" ListBox as per ca8msm
  Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

    ListBox1.Visible = False
    If e.KeyCode = Keys.OemPeriod Or e.KeyCode = Keys.Decimal Then
      Dim curPoint As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
      curPoint.Offset(RichTextBox1.Left, RichTextBox1.Top + RichTextBox1.SelectionFont.Height)
      ListBox1.Location = curPoint
      'ListBox1.Visible = Not ListBox1.Visible
      ListBox1.Visible = True
      ListBox1.BringToFront()
      ListBox1.Focus()
    End If

  End Sub

  'I don't think this is needed
  'Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

  '  ListBox1.Visible = False

  'End Sub

  Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

    RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
    ListBox1.Visible = False

  End Sub

  Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress

    'Accept Enter or Space as selection key
    If e.KeyChar = Convert.ToChar(Keys.Enter) Or e.KeyChar = Convert.ToChar(Keys.Space) Then
      RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
      ListBox1.Visible = False
    Else
      ListBox1.SelectedIndex = ListBox1.FindString(e.KeyChar, 0)
    End If

  End Sub


  'Hide the ListBox when it loses focus
  'However it wont lose focus if you click on a control that doesn't get focussed so ...
  'The Form (and probably any Panels would need Click Event Handlers to hide the ListBox
  Private Sub ListBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.LostFocus

    ListBox1.Visible = False

  End Sub

  Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click

    ListBox1.Visible = False

  End Sub

So now we just have to keep a record of the keypresses so that we can echo them into the RichTextBox as they are typed (including handling BackSpace and Delete) and then IF a selection is made replace the echoed characters with the SelectedItem.

[vampire][bat]
 
Wow, you people have gone a long way..
I need a little time to understand all those.
I too interested with the floating listbox.
Let me try it and tell you the result.

May be first attempt in the VB.NET community to create something like this. I have searched a lot for it found nothing.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
While the floating listbox working, there are some points to tell.
1) It is still appearing at the left-top corner.
2) changing the ritchtextbox to textbox need some changes
Code:
curPoint.Offset(RichTextBox1.Left, RichTextBox1.Top + RichTextBox1.SelectionFont.Height)
TO
curPoint.Offset(TextBox1.Left, TextBox1.Top)

but then listbox appears at the back side of the textbox and at the left-top

Wish you success on more development


________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Here is an interesting one.

drag-drop working with right mouse.

May be you people can make use of the API. (I am not able to)

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
I saw that article Zameer, but the way that E%F started to do this was by using a RichTextBox, not a standard TextBox, as the GetPositionFromCharIndex method was very helpful in returning the coordinates of where the cursor is (and this isn't available in a standard Textbox, hence why it doesn't work).

It shouldn't still be appearing in the top left corner like you said in #1 though...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Still listbox appears at the left-top corner of the RichTextBox not where the cursor is.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
I'm not sure what code you are using then. I just created a new form named Form5.vb, copied my code from above and pasted it over the existing code for my new form. Worked perfectly.

Once you've done that, have a look at the enhancements that E&F has made and incorporate them into your form...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
OK, here's another slight extension (again with the whole code for the form) that incorporates E&F's suggestions and now allows the user to "escape" out of the ListBox:
Code:
Public Class Form5
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SuspendLayout()
        '
        'RichTextBox1
        '
        Me.RichTextBox1.Location = New System.Drawing.Point(16, 24)
        Me.RichTextBox1.Name = "RichTextBox1"
        Me.RichTextBox1.Size = New System.Drawing.Size(256, 216)
        Me.RichTextBox1.TabIndex = 0
        Me.RichTextBox1.Text = ""
        '
        'ListBox1
        '
        Me.ListBox1.Items.AddRange(New Object() {"Item1", "Item2"})
        Me.ListBox1.Location = New System.Drawing.Point(96, 88)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(120, 95)
        Me.ListBox1.TabIndex = 1
        Me.ListBox1.Visible = False
        '
        'Form5
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.RichTextBox1)
        Me.KeyPreview = True
        Me.Name = "Form5"
        Me.Text = "Form5"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

        ListBox1.Visible = False
        If e.KeyCode = Keys.OemPeriod Or e.KeyCode = Keys.Decimal Then
            Dim curPoint As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
            curPoint.Offset(RichTextBox1.Left, RichTextBox1.Top + RichTextBox1.Font.Height)
            ListBox1.Location = curPoint
            ListBox1.Visible = True
            ListBox1.BringToFront()
            ' Added a focus event
            ListBox1.Focus()
        End If

    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
        ListBox1.Visible = False
    End Sub

    Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress
        'Accept Enter or Space as selection key
        If e.KeyChar = Convert.ToChar(Keys.Enter) Or e.KeyChar = Convert.ToChar(Keys.Space) Then
            RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
            ListBox1.Visible = False
            ' Let the user go back to the RTB by pressing escape
        ElseIf e.KeyChar = Convert.ToChar(Keys.Escape) Then
            ListBox1.Visible = False
            RichTextBox1.Focus()
        Else
            ListBox1.SelectedIndex = ListBox1.FindString(e.KeyChar, 0)
        End If
    End Sub

    Private Sub ListBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.LostFocus
        ListBox1.Visible = False
    End Sub

    ' Add a click event to hide the ListBox as per E&F's comments
    ' This still needs to be added to other panels/controls that exist
    Private Sub Form5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        ListBox1.Visible = False
    End Sub

    ' Set a default entry for the ListBox so when it pops up
    ' the user can use up/down arrows to navigate the items
    Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.SelectedItem = ListBox1.Items(0)
    End Sub
End Class


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Morning, all. I don't think I'll get much chance to experiment during the day (but I will be keeping an eye on progress). I'll definitely work on it again tonight - and if we can end up with a control or class as c8msm suggested that will be brilliant.

[vampire][bat]
 
By the way, does anyone know of a good way (i.e. has someone already created something like this?!) to create the necessary TGML that will keep the colour formatting when pasting code within [&#91;]CODE][&#91;]/CODE] tags? It would just make the above so much easier to read...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, If you go to my home page you will find an exe (both excutable and installable) created in VB6.

Try CTRL+L feature to access the list box. which is your list of custom text

Infact to tell you truth, I am trying the same in .net using vb2005

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Thanks Zameer - I'll take a look shortly.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Just the changes to ca8msm's last code:

Code:
  Private SearchString As String
  Private CurrentPosition As Integer

  Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

    ListBox1.Visible = False
    If e.KeyCode = Keys.OemPeriod Or e.KeyCode = Keys.Decimal Then
      CurrentPosition = RichTextBox1.SelectionStart
      SearchString = ""
      Dim curPoint As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
      curPoint.Offset(RichTextBox1.Left, RichTextBox1.Top + RichTextBox1.[b]SelectionFont[/b].Height)
      ListBox1.Location = curPoint
      ListBox1.Visible = True
      ListBox1.BringToFront()
      ' Added a focus event
      ListBox1.Focus()
    End If

  End Sub

  Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

    RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
    ListBox1.Visible = False

  End Sub

  Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress

    'Accept Enter or Space as selection key
    If e.KeyChar = Convert.ToChar(Keys.Enter) Or e.KeyChar = Convert.ToChar(Keys.Space) Then
      Dim x As Integer = RichTextBox1.SelectionStart - CurrentPosition
      RichTextBox1.SelectionStart = CurrentPosition
      RichTextBox1.SelectionLength = x
      RichTextBox1.Cut()
      RichTextBox1.AppendText(ListBox1.SelectedItem.ToString + " ") 'add a space to the end of the string
      ListBox1.Visible = False
      ' Let the user go back to the RTB by pressing escape
    ElseIf e.KeyChar = Convert.ToChar(Keys.Escape) Then
      ListBox1.Visible = False
      RichTextBox1.Focus()
    Else
      'Keep it simple for now(Delete, Left and Right can be handled later if anyone is  brave enough)
      'We'll just assume the character is proper text
      RichTextBox1.AppendText(e.KeyChar)
      SearchString += e.KeyChar
      ListBox1.SelectedIndex = ListBox1.FindString(SearchString, 0)
    End If

  End Sub

  Private Sub ListBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.LostFocus

    ListBox1.Visible = False

  End Sub

  ' Add a click event to hide the ListBox as per E&F's comments
  ' This still needs to be added to other panels/controls that exist
  Private Sub Form5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click

    ListBox1.Visible = False

  End Sub

  ' Set a default entry for the ListBox so when it pops up
  ' the user can use up/down arrows to navigate the items
  Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ListBox1.SelectedItem = ListBox1.Items(0)

  End Sub

Now we need to work out how to handle Backspace, Delete, Left and Right. Then convert it to a control.

Zameer, this is in VS2003. I can't see that MS would have made any changes in VS2005 that would prevent any of this from working.

ca8msm, when we've got this working, it shouldn't be a big leap to set it so that it will insert the colour codes for us.

Hope this helps.

[vampire][bat]
 
I've done a bit more on this, this evening. I've added the facility for optionally prepending and appending a space and making sure that the ListBox fits within the size constraints of the Form (although that can easily be changed to set the constraints to the RichTextBox). I'm now looking at support for Left, Right, Delete and Backspace, which I should be able to get done over the weekend. I wont bother posting what I have at the moment, I'll leave it until I've finished. When that's done it should be a relatively trivial task to convert it into a control.

[vampire][bat]
 
Zameer, you said earlier that you were having some problems with the posted code in 2005. I think I get my 2005 disks in the MSDN December shipment so I haven't bothered to download it - I have however downloaded and installed the Express Edition and tested the last posted code, which seems to work fine.

Hope this helps.

[vampire][bat]
 
E&F, Thanks for the updates.
I am using Express edition.(I don't have vs2003 or vs2005) Everything else work fine except the listbox's appearing location. It is just down to the fisrt line regardless of the line where you type. If you select an item from the list then it adds to correct line.

also if you press backspace, keeping the list visible, adds a char in square shape for each press.

I have "SharpDevelope" at home need to try on that.
Thanks

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Zameer, although I've done a bit more in 2003, this is the complete version that I currently have in 2005 (Express).

By the way, the way I intially created it was to create a new project in 2005 Express, delete the default Form1 and add a new Form5. Copy my 2003 code into the code window for Form5 in 2005. I then compiled it and it complained with an error (I can't remember what it was but I think it was to do with duplicate declarations.) Double clicked the error and it opened another code window with an empty Form5 class declaration. I just deleted that and it ran OK.

This is the complete 2005 Express code (as I said a couple of features missing but I'm still working on those in 2003). If you test this, you should find the listBox does appear at the cursor position.

Code:
Public Class Form5
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
	Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
	Friend WithEvents chkAppendSpace As System.Windows.Forms.CheckBox
	Friend WithEvents chkPrependSpace As System.Windows.Forms.CheckBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
		Me.ListBox1 = New System.Windows.Forms.ListBox
		Me.chkAppendSpace = New System.Windows.Forms.CheckBox
		Me.chkPrependSpace = New System.Windows.Forms.CheckBox
		Me.SuspendLayout()
		'
		'RichTextBox1
		'
		Me.RichTextBox1.Location = New System.Drawing.Point(16, 24)
		Me.RichTextBox1.Name = "RichTextBox1"
		Me.RichTextBox1.Size = New System.Drawing.Size(464, 288)
		Me.RichTextBox1.TabIndex = 0
		Me.RichTextBox1.Text = ""
		'
		'ListBox1
		'
		Me.ListBox1.Items.AddRange(New Object() {"Fred", "John", "Sue", "Anne", "Roy", "Alison", "Richard", "Robert", "Adam", "James"})
		Me.ListBox1.Location = New System.Drawing.Point(96, 88)
		Me.ListBox1.Name = "ListBox1"
		Me.ListBox1.Size = New System.Drawing.Size(120, 95)
		Me.ListBox1.TabIndex = 1
		Me.ListBox1.Visible = False
		'
		'chkAppendSpace
		'
		Me.chkAppendSpace.Location = New System.Drawing.Point(528, 56)
		Me.chkAppendSpace.Name = "chkAppendSpace"
		Me.chkAppendSpace.TabIndex = 2
		Me.chkAppendSpace.Text = "Append Space"
		'
		'chkPrependSpace
		'
		Me.chkPrependSpace.Location = New System.Drawing.Point(528, 104)
		Me.chkPrependSpace.Name = "chkPrependSpace"
		Me.chkPrependSpace.TabIndex = 3
		Me.chkPrependSpace.Text = "Prepend Space"
		'
		'Form5
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(704, 341)
		Me.Controls.Add(Me.chkPrependSpace)
		Me.Controls.Add(Me.chkAppendSpace)
		Me.Controls.Add(Me.ListBox1)
		Me.Controls.Add(Me.RichTextBox1)
		Me.KeyPreview = True
		Me.Name = "Form5"
		Me.Text = "Form5"
		Me.ResumeLayout(False)

	End Sub

#End Region

	Private SearchString As String
	Private CurrentPosition As Integer
	Private PrependSpace As Boolean
	Private AppendSpace As Boolean

	Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

		ListBox1.Visible = False
		If e.KeyCode = Keys.OemPeriod Or e.KeyCode = Keys.Decimal Then
			CurrentPosition = RichTextBox1.SelectionStart
			SearchString = ""
			AppendSpace = chkAppendSpace.Checked
			PrependSpace = chkPrependSpace.Checked
			Dim curPoint As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
			curPoint.Offset(RichTextBox1.Left, RichTextBox1.Top + RichTextBox1.SelectionFont.Height)
			ListBox1.Location = curPoint
			ListBox1.Visible = True
			ListBox1.BringToFront()
			' Added a focus event
			ListBox1.Focus()
		End If

	End Sub

	Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

		RichTextBox1.AppendText(ListBox1.SelectedItem.ToString)
		ListBox1.Visible = False

	End Sub

	Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown

        'Holding place for Cursor Key handler
		Select Case e.KeyCode
			Case Keys.Left
				e.Handled = False
			Case Keys.Right
				e.Handled = False
			Case Keys.Back
				e.Handled = True
			Case Keys.Delete
				e.Handled = True
			Case Else
				e.Handled = False
		End Select

	End Sub

	Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress

		'Accept Enter or Space as selection key
		If e.KeyChar = Convert.ToChar(Keys.Enter) Or e.KeyChar = Convert.ToChar(Keys.Space) Then
			Dim x As Integer = RichTextBox1.SelectionStart - CurrentPosition
			RichTextBox1.SelectionStart = CurrentPosition
			RichTextBox1.SelectionLength = x
			RichTextBox1.Cut()
			Dim TailSpace As String = IIf(AppendSpace, " ", "").ToString
			Dim StartSpace As String = IIf(PrependSpace, " ", "").ToString
			RichTextBox1.AppendText(StartSpace + ListBox1.SelectedItem.ToString + TailSpace) 'add a space to the end of the string
			ListBox1.Visible = False
			RichTextBox1.Focus()
			' Let the user go back to the RTB by pressing escape
		ElseIf e.KeyChar = Convert.ToChar(Keys.Escape) Then
			ListBox1.Visible = False
			RichTextBox1.Focus()
		Else
			'Keep it simple for now(Delete, Left and Right can be handled later if anyone is  brave enough)
			'We'll just assume the character is proper text
			RichTextBox1.AppendText(e.KeyChar)
			SearchString += e.KeyChar
			ListBox1.SelectedIndex = ListBox1.FindString(SearchString, 0)
		End If

	End Sub

	Private Sub ListBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.LostFocus

		ListBox1.Visible = False

	End Sub

	' Add a click event to hide the ListBox as per E&F's comments
	' This still needs to be added to other panels/controls that exist
	Private Sub Form5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click

		ListBox1.Visible = False

	End Sub

	' Set a default entry for the ListBox so when it pops up
	' the user can use up/down arrows to navigate the items
	Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

		ListBox1.SelectedItem = ListBox1.Items(0)

	End Sub

	Private Sub chkPrependSpace_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkPrependSpace.CheckedChanged

		RichTextBox1.Focus()

	End Sub

	Private Sub chkAppendSpace_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAppendSpace.CheckedChanged

		RichTextBox1.Focus()

	End Sub

End Class

Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top