• <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)//取控件里鼠標所在行的命令發送后提到最前
             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            //處理剩下的字符串,注意把開頭結尾的"\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        }
              

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

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

            <2008年10月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久久久久中文字幕| 久久99国产精品一区二区| 丁香五月网久久综合| 国产精品免费久久久久久久久| 婷婷久久综合| 品成人欧美大片久久国产欧美...| 国产精品成人精品久久久| 久久免费视频1| 91久久国产视频| 欧美一区二区精品久久| 久久国产精品77777| 一本久久a久久精品亚洲| 久久亚洲国产精品123区| 中文字幕亚洲综合久久| 久久精品中文字幕大胸| 久久最近最新中文字幕大全| 香蕉aa三级久久毛片| 日韩精品久久久久久| 久久久久久久女国产乱让韩 | 久久精品国产亚洲AV不卡| 久久国产亚洲精品无码| 亚洲精品成人久久久| 日韩亚洲国产综合久久久| 高清免费久久午夜精品| 久久人与动人物a级毛片| 久久精品免费网站网| 日本免费久久久久久久网站| 久久亚洲AV成人无码国产| 久久久91精品国产一区二区三区| 久久99精品国产麻豆宅宅| 一级a性色生活片久久无| 久久高潮一级毛片免费| 成人精品一区二区久久| 91久久香蕉国产熟女线看| 94久久国产乱子伦精品免费| 韩国无遮挡三级久久| 人人狠狠综合久久亚洲婷婷| 久久久九九有精品国产| 伊人色综合久久| 久久亚洲国产精品123区| 国产精品亚洲综合久久|