Change CaretIndex for 2.0

Posted by pipelinecache on Stack Overflow See other posts from Stack Overflow or by pipelinecache
Published on 2010-04-07T13:40:48Z Indexed on 2010/04/07 13:43 UTC
Read the original article Hit count: 135

Filed under:
|

Hi everyone,

I'm having a problem that I don't want use .NET Framework 3.0/3.5 allready. So I want to change the CaretIndex for something usefull in 2.0?

Does anyone have an idea how to do this. This is the CaretIndex example I have:

Regex reg = new Regex(@"^\d{1,10}$", RegexOptions.Singleline);
        TextBox textBox = sender as TextBox;

        if (textBox.Text == string.Empty)
        {
            return;
        }

        string newText = reg.Replace(textBox.Text, string.Empty);
        if (newText != textBox.Text)
        {

            int caretIndex = textBox.CaretIndex ;
            textBox.Text = newText;
            if (caretIndex > 0) { textBox.CaretIndex = caretIndex - 1; }
        }

© Stack Overflow or respective owner

Related posts about c#2.0

Related posts about ASP.NET