C # Move cursor to RichTextBox with right mouse button

I have a RichTextBox control. When you left-click in the text, the cursor will move to where you clicked. I want this to happen when I right-clicked. I am not sure how to do this. Thank!

+3
source share
1 answer

Assuming winforms:

Implement the MouseUp event handler as follows:

private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        RichTextBox box = (RichTextBox)sender;
        box.SelectionStart = box.GetCharIndexFromPosition(e.Location);
        box.SelectionLength = 0;
    }
}
+6
source

Source: https://habr.com/ru/post/1748997/


All Articles