I have a textbox that does autocompletion like so:
txtName.AutoCompleteMode = AutoCompleteMode.Suggest;
txtName.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtName.AutoCompleteCustomSource = namesCollection;
It works, but only at the beginning of a textbox. I'd like autocomplete to kick in for any word the user is entering, at any position in the textbox.
Sample Usage
I made a few changes to the solution proposed by @PaRiMaL RaJ because the list box was not being displayed when the text box was inside a UserControl that was not tall enough. Basically, instead of adding the list box to the parent of the text box, I added to the form and I calculate the absolute position in the form.
The other solutions didn't work for me in a multiline environment to my needs, so I've added to @Francisco Goldenstein's answer to enable this. What I needed was to autocomplete any 'word' in the TextBox and in any position/line. After minimal testing, this class seems to work well enough for me in a multiline TextBox. Hope it helps someone.
Main changes are in
UpdateListBox()
andthis_KeyDown()
, to deal with the 'current' word, i.e. the one just before the caret position, rather than the entire textbox contents.Change the definition of
separators
inUpdateListBox()
to suit your needs.