Position of the cursor and TextChanged event

Two additional lines are needed if we want to make cursor stay at the end of the line when editing content of TextBox in TextChanged event.

private void textBox_TextChanged(object sender, TextChangedEventArgs e)
    TextBox txtb = (sender as TextBox);
    // remember cursor location
    int loc = txtb.SelectionStart;
    // do something with txtb.Text;
    txtb.Text = txtb.Text.Replace('$','%');
    // set old location
    txtb.SelectionStart = loc;

0 Responses to “Position of the cursor and TextChanged event”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s



%d bloggers like this: