0

在表单中放置一个 RichTextBox 后(使用 VS 2008 并使用默认值),我可以输入文本并选择它,无论是从头到尾拖动鼠标还是首先选择文本的结尾并拖动到开头。但是,如果我将 SelectionChanged 中的 RichTextBox SelectionStart 属性设置为其值,则从输入文本的末尾拖动到开头时,选择不会正确突出显示。它一次突出显示(选择)一个单词。为什么?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void richTextBox1_SelectionChanged(object sender, EventArgs e)
        {
            // With this line, text is not selected properly with dragging "up".
            // It is selected when dragging down.  Why?
            richTextBox1.SelectionStart = richTextBox1.SelectionStart;
        }
    }
}
4

0 回答 0