Cannot use the backspace in the AutoCompletion-VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KelvinNyota
    New Member
    • Nov 2015
    • 5

    Cannot use the backspace in the AutoCompletion-VB.NET

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

    The cursor gets very sticky when you press the backspace to correct an error.

    Sometimes the words are hidden and you cannot see what you're typing after deleting text.


    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 dictionary link from here:



    Here is my code:

    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 KelvinNyota; Nov 28 '15, 05:14 PM. Reason: Adding my dictionary link
Working...