Solved

is there any way to set the cursor in a textbox after setting the .Text property?

Posted on 2008-10-07
3
176 Views
Last Modified: 2010-04-23
I have a textbox control which I use the TextChanged event to filter out certain keypresses which I don't want to show by taking the text as a string with each keypress and filtering out any unwanted chars. The problem is that when I insert the string back into the textbox, the cursor is always at the end of the current string. Is there anyway to remember the cursor position so the user can edit the string? On second thought, I may have to rethink my whole approach.

Dan
0
Comment
Question by:zliminator
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 250 total points
ID: 22660391
Cursor position can be readed and writed using SelectionStart property. Try it.
0
 

Author Comment

by:zliminator
ID: 22661026
I found a SelectionStart property for the ComboBox but not for the TextBox. I'm using .Net 2.0. Is this new to 3.x? I tried it like this:
Private Sub DisplayTextBox_TextChanged(ByVal sender As System.Object, ByVal e As    System.EventArgs) Handles DisplayTextBox.TextChanged
        Dim x As Integer = DisplayTextBox.SelectionStart
but it allway gives 0

Dan
0
 

Author Comment

by:zliminator
ID: 22661083
OK, I can set it but I can't get it. All I need to do, really, is set it. I'm happy.

Dan
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now