Results 1 to 1 of 1

Thread: AutoCompletion does not work when you press the BackSpace

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    114

    AutoCompletion does not work when you press the BackSpace

    I have this problem with my Autocompletion program in VB.NET where you cannot delete text after Autocompletion is done because once you do that, you cannot Autocomplete again:

    The cursor gets very sticky after deletion, and you may sometimes not see the text that you are typing.

    Here is what needs to be done:


    For instance: the text is entered into a TextBox (not the RichTextBox), because it is the one with the AutoComplete functionality, and that text is only put into the RichTextBox when you enter a space (after checking if it needs to be replaced).

    If you BackSpace to the start of the textbox and press BackSpace again then you need to hide the TextBox and select the appropriate point in the RichTextBox to edit.

    You then need to define a way for the user to seamlessly re-enter the mode where entry is in to the TextBox and AutoComplete and Replacement are active again.

    Get my wordlist from here:

    https://onedrive.live.com/redir?resi...int=file%2ctxt

    Here is my code:


    HTML Code:
        Imports System.IO
    
    Public Class Form1
    
        'This is where you rename a RichTextBox and give it a location'
        Private rtb As New RichTextBox With {.Location = New Point(20, 20), .Dock = DockStyle.Fill}
    
    
        'Here you create a textbox and rename is as tb'
        Private WithEvents tb As New TextBox With {.BorderStyle = BorderStyle.None}
    
    
        'This the AutoCompleteList is the new list for  the function AutoCompleteStringCollection'
        Private AutoCompleteList As New AutoCompleteStringCollection
    
    
    
        'This one here is for the Replacement List'
        Private ReplacementList As New Dictionary(Of String, String)
    
    
        Private SelStart As Integer
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'This is where you declare the width of the form and location'
    
            Width = 900
            CenterToScreen()
    
            'Here is adding the TextBox into the RichTextBox which is Called tb'
            Controls.AddRange(New Control() {rtb, tb})
    
            'This I think is where to start counting in order to tell the textbox that, that is a line'
            For count As Integer = 1 To 10000
                AutoCompleteList.Add("Line " & count.ToString)
            Next
    
    
    
            Dim inputFile As String = "C:\Users\Acer\Desktop\out.txt"
    
            If File.Exists(inputFile) Then
    
    
                Using sr As New StreamReader(inputFile)
                    While Not sr.EndOfStream
                        Dim wordParts = sr.ReadLine()
                        If wordParts.Count >= 1 Then
    
                            AutoCompleteList.Add(wordParts.ToString)
                        End If
                    End While
                End Using
    
            End If
    
    
    
            tb.AutoCompleteCustomSource = AutoCompleteList
            tb.AutoCompleteMode = AutoCompleteMode.Suggest
            tb.AutoCompleteSource = AutoCompleteSource.CustomSource
            rtb.Controls.Add(tb)
            tb.Location = New Point(0, 0)
            tb.Select()
        End Sub
        Private Sub tb_TextChanged(sender As Object, e As System.EventArgs) Handles tb.TextChanged
            Dim Txt As String
            If Not String.IsNullOrEmpty(tb.Text) Then
                If tb.Text.EndsWith(" ") Then
                    If ReplacementList.ContainsKey(tb.Text.TrimEnd) Then
                        Txt = ReplacementList(tb.Text.TrimEnd)
                    Else
                        Txt = tb.Text
                    End If
                    rtb.SelectedText = Txt & " "
                    SelStart = rtb.TextLength
                    tb.Location = rtb.GetPositionFromCharIndex(rtb.TextLength)
                    tb.Text = ""
                End If
            End If
        End Sub
    End Class
    Last edited by nqioweryuadfge; Nov 28th, 2015 at 12:11 PM. Reason: Adding a dictionary link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width