开发者

C# Moving Cursor in RichTextBox on Right-Click

开发者 https://www.devze.com 2023-01-02 12:10 出处:网络
I have a RichTextBox co开发者_StackOverflow中文版ntrol. When you left-click in the text the cursor jumps to where you clicked. I want this to happen when I right-click as well. I\'m not sure how to do

I have a RichTextBox co开发者_StackOverflow中文版ntrol. When you left-click in the text the cursor jumps to where you clicked. I want this to happen when I right-click as well. I'm not sure how to do this. Thanks!


Assuming winforms:

Implement a MouseUp event handler like so:

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;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消