VB.net Insert Text where user is typing in middle of text box

Hi

I have a text box where I want to insert text in the middle of the box programmatically, where the user is typing.
What VB.net code would I use to do this?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi  murbro;

Not knowing exactly what you are trying to achieve here I do not know how well this is going to work for you. The reason being is that the Form is running in a single thread and as the user is typing in the box it is handling the keyboard stroke from the user. So from the question it sounds like some other code is monitoring the user input to figure out when to interrupt the user to insert some text. This other code could not be running in the same thread because in a single thread one segment of code will be running at any given time.

It would be more helpful if you can tell us more of what you are trying to achieve with this.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
where the user is typing

Typically you'd simply set the TextBox.SelectedText() property.  If nothing is selected, then the text will be inserted where the cursor is located.  If something is selected, it would replace that selected text.

Simple example:
TextBox1.SelectedText = "your text to insert here"

Open in new window

Fernando SotoRetiredCommented:
Hi  murbro;

In my solution I may have wrongly assumed that you wanted to do this as the user was typing into the TextBox. If that is an incorrect assumption please restate the question.

Thanks.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi Fernando. Your assumption was right. I do want to do that. At the moment when the user types # a form pops up. They select an item that then replaces the #. I am not sure if this is the best way to do this, because there may be another # in the textbox
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
When the user presses #, store the current SelectionStart() value as it will tell you where the # was pressed at.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Mike. Great answer
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.