拖动鼠标时RichTextBox SelectionLength变得怪异

时间:2012-09-08 06:30:19

标签: c# winforms richtextbox

在表单中放置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;
        }
    }
}

0 个答案:

没有答案