5

我有一个 RichTextBox 控件。当您在文本中左键单击时,光标会跳到您单击的位置。我也希望在我右键单击时发生这种情况。我不知道该怎么做。谢谢!

4

1 回答 1

9

假设winforms:

像这样实现 MouseUp 事件处理程序:

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;
    }
}
于 2010-06-08T11:05:06.310 回答