Click here to Skip to main content
15,917,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get rtb.SelectionStart when pressing the keys: up, down, left, right.I can get it when I press: Left, Right.But I just get it when I press up 2 times.
C#
//store SelectionStart
public int ise=0;
//richTextBox1_TextChanged:
ise = richTextBox1.SelectionStart;

C#
//keydown
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
            if (e.KeyCode == Keys.Left || e.KeyCode==Keys.Right)
            {
                ise = richTextBox1.SelectionStart;
                textBox1.Text = string.Format("select start:{0}", ise.ToString());
            }
            if (e.KeyCode == Keys.Up)
            {
                ise = richTextBox1.SelectionStart;
                textBox1.Text = string.Format("select start:{0}", ise.ToString());
            }
            if (e.KeyCode == Keys.Down)
            {
                ise = richTextBox1.SelectionStart;
                textBox1.Text = string.Format("select start:{0}", ise.ToString());
            }
}
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900