CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2015
    Location
    Kenya
    Posts
    11

    Cannot Autocomplete again After deleting text with the Backspace-VB.NET

    I have this problem with my Autocompletion program in VB.NET where you cannot delete text eazily after Autocompletion is done because once you do that, you may not be able to Autocomplete again. The cursor is very sticky when you press the backspace.

    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.


    Check my wordlist link:. wordlist link


    Here is my 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; November 28th, 2015 at 12:13 PM. Reason: I have added a link to my dictionary file

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

Featured