winform程序,有一个textbox,当在textbox中选中内容后我如何判断鼠标是否在选中的内容上面呢?

解决方案 »

  1.   

    Focus()或者Selected.lenght=0可以吧。。
      

  2.   

    textbox里有很多内容,有点被选中了,有的没选中,如何判断鼠标在选中的内容上面
      

  3.   

    貌似难,你得重写TextBox控件。
    你可获取选中的内容,然后将该内容转变为一个基础控件,这样你才能捕获它。
      

  4.   

    在鼠标的移动事件里写代码,我这里只写了单行文本的,多行的要麻烦一些
    private void textBox1_MouseMove(object sender, MouseEventArgs e)
            {            int start = textBox1.SelectionStart;
                int length = textBox1.SelectionLength;
                //获取选择字符串的矩形
                Rectangle rect = new Rectangle();
                rect.X = start * 6;//6是单个字符的宽度
                rect.Y = 0;
                rect.Width = length * 6;
                rect.Height = 14;//14是单个字符的高度
                //判断矩形是否包含鼠标坐标
                if (rect.Contains(e.Location))
                    Console.WriteLine(rect + " " + i++);
            }
    试试,是你要的效果