textbox 中可输入很多字符。当我用鼠标选定某些字符时,在提交后如何获得我选定的那些字符????

解决方案 »

  1.   

    使用TextBox的SelectedText属性
    C#代码如下,已经在VS2005环境下运行通过:if (textBox1.SelectedText.Length == 0)
                {
                    MessageBox.Show("请先选择字符", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
       textBox2.Text = textBox1.SelectedText.Trim(); 
      

  2.   

       string str = TextBox.SelectedText;
       int index = TextBox.SelectionStart;
       string s= TextBox.Text;
       s= s.Substring(0, index + str.Length - 1);
      

  3.   

    webfrom下好像没有SelectedText 这个属性吧!!!!!
      

  4.   

     private void textBox1_MouseLeave(object sender, EventArgs e)
            {
                if (textBox1.SelectedText.Length == 0)
                {
                    MessageBox.Show("请先选择字符", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                textBox2.Text = textBox1.SelectedText.Trim(); 
            }
      

  5.   

    webFrom下JS代码如下<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        <script language=javascript>
            function getSelText() {
                var txt = '';
                if (window.getSelection) {
                    txt = window.getSelection();
                }
                else if (document.getSelection) {
                    txt = document.getSelection();
                }
                else if (document.selection) {
                    txt = document.selection.createRange().text;
                }
                else return;
                //document.getElementById(selectedtext).value = txt;
                alert(txt);
            }
        </script>
        
    </head>
    <body>
    <form name=aform >
     <input type="button" value="Get selection" onmousedown="getSelText()"> 
     <textarea name="selectedtext" rows="5" cols="20"></textarea>
    </form>
    </body>
    </html>