• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 124,  comments - 29,  trackbacks - 0

             

             1 private void GetLine(TextBox txtCmdInput)//取控件里鼠標所在行的命令發(fā)送后提到最前
             2        {
             3            //取光標所在行的字符串包括末尾的換行回車符"\r\n"
             4            string strCmdText = txtCmdInput.Text;
             5            int curInx = txtCmdInput.SelectionStart;       //光標所在位置索引
             6            string tmp = strCmdText.Substring(0, curInx);  //開始到光標處的子串
             7            int start = tmp.LastIndexOf('\n');             //找光標所在行的開頭索引start + 1
             8
             9            tmp = strCmdText.Substring(curInx);//當前光標所在位置到最后的子串
            10            int end = tmp.IndexOf('\n'); //找該行的末尾索引包括"\r\n"
            11            string curRowText = null;
            12            if (end > 0)
            13            {
            14                curRowText = strCmdText.Substring(start + 1, curInx - start + end);
            15            }

            16            else
            17            {
            18                curRowText = strCmdText.Substring(start + 1);
            19            }

            20            //把光標所在行的命令提到第一行的下一行
            21            String strLeft = strCmdText.Remove(start + 1, curRowText.Length);
            22
            23            //處理剩下的字符串,注意把開頭結(jié)尾的"\r\n"找到刪掉
            24            if (strLeft != "")
            25            {
            26                while (strLeft[strLeft.Length - 1== '\r' || strLeft[strLeft.Length - 1== '\n')
            27                {
            28                    strLeft = strLeft.Remove(strLeft.Length - 11);
            29                }

            30            }

            31            if (strLeft != "")
            32            {
            33                while (strLeft[0== '\r')
            34                {
            35                    strLeft = strLeft.Remove(02);
            36                }

            37            }

            38            //處理你取出的當前行的字符串若有"\r\n"注意把它去掉
            39            if (curRowText != "" && curRowText.Length > 0)
            40            {
            41                while (curRowText[curRowText.Length - 1== '\r' || curRowText[curRowText.Length - 1== '\n')
            42                {
            43                    curRowText = curRowText.Remove(curRowText.Length - 11);
            44                }

            45            }

            46            String strNew = curRowText + "\r\n" + strLeft;
            47            //最后前面留一行空格且把鼠標定位到此
            48            txtCmdInput.Text = "\r\n" + strNew;
            49        }
              

            接著引發(fā)textbox控件的KeyDown事件
                    private void txtCmdInput_KeyDown(object sender, KeyEventArgs e)
                    {
                        if (e.KeyCode == Keys.Enter)
                        {
                            //發(fā)送光標所在行指令,且把它提到頭一行
                            GetLine(txtCmdInput);
                            e.SuppressKeyPress = true;//回車事件已經(jīng)處理完不再響應(yīng)了
                        }
                    }
            posted on 2008-09-03 15:09 天書 閱讀(4943) 評論(3)  編輯 收藏 引用

            FeedBack:
            # re: C# 多行textbox 按回車鍵提取光標所在行字符串且在最上面一行顯示,光標回歸第一行
            2009-02-27 13:59 | 斯比克
            學(xué)習(xí)~~  回復(fù)  更多評論
              
            # re: C# 多行textbox 按回車鍵提取光標所在行字符串且在最上面一行顯示,光標回歸第一行
            2009-02-27 14:01 | 斯比克
            呵呵,雖然不是我需要的效果..但是給我提供了思路...3Q...  回復(fù)  更多評論
              
            # re: C# 多行textbox 按回車鍵提取光標所在行字符串且在最上面一行顯示,光標回歸第一行
            2009-10-09 18:02 | 我們學(xué)習(xí)網(wǎng)
            按回車光標轉(zhuǎn)向下一控件。  回復(fù)  更多評論
              

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久成人国产精品免费软件| 亚洲精品白浆高清久久久久久| 久久精品国产亚洲av高清漫画| 欧美午夜精品久久久久免费视| 97久久超碰成人精品网站| 美女写真久久影院| 亚洲国产成人久久精品99| 人妻精品久久久久中文字幕69| 久久久久中文字幕| 久久久久久久97| 99久久免费国产精品| 亚洲精品无码久久千人斩| 久久国产综合精品五月天| 久久久老熟女一区二区三区| 国产精品va久久久久久久| 亚洲AV乱码久久精品蜜桃| 久久福利片| 91麻精品国产91久久久久| 亚洲国产另类久久久精品小说| 精品人妻伦九区久久AAA片69| 亚洲综合日韩久久成人AV| 久久精品亚洲男人的天堂| 久久精品人人做人人爽电影蜜月 | 狼狼综合久久久久综合网| 日韩中文久久| 色综合久久中文色婷婷| 99久久人妻无码精品系列蜜桃| 久久久久久亚洲精品影院| 欧美成a人片免费看久久| 成人a毛片久久免费播放| 精品蜜臀久久久久99网站| 日韩乱码人妻无码中文字幕久久| 国产精品一区二区久久精品涩爱 | 五月丁香综合激情六月久久| 色偷偷88欧美精品久久久| 久久免费国产精品| 欧洲国产伦久久久久久久| 久久亚洲电影| 亚洲中文字幕无码一久久区| 久久久久久久精品妇女99| 欧美一区二区三区久久综合|