• <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久久精品午夜一区二区| 国产—久久香蕉国产线看观看| 色综合久久88色综合天天 | 久久香蕉国产线看观看精品yw| 91性高湖久久久久| 无码人妻精品一区二区三区久久久| 久久青青草原国产精品免费| 国内精品久久久久影院薰衣草| 国产精自产拍久久久久久蜜| 久久天天躁狠狠躁夜夜96流白浆| 亚洲色欲久久久久综合网| 精品九九久久国内精品| 天天躁日日躁狠狠久久| 久久亚洲精品无码aⅴ大香| 久久99精品久久久久久不卡 | 久久天天躁狠狠躁夜夜2020一| 热99re久久国超精品首页| 久久精品国产久精国产思思| 久久精品中文字幕大胸| 久久精品一区二区三区中文字幕 | 最新久久免费视频| 欧美精品丝袜久久久中文字幕| 天天久久狠狠色综合| 久久91综合国产91久久精品| 久久综合狠狠综合久久综合88| 久久精品国产2020| 久久精品国产乱子伦| 99久久精品国产一区二区| 久久久久久综合网天天| 久久伊人五月丁香狠狠色| 久久久国产亚洲精品| 久久久久久伊人高潮影院| 色88久久久久高潮综合影院| 漂亮人妻被黑人久久精品| 久久精品人成免费| 色综合久久中文色婷婷| 国产午夜福利精品久久| 亚洲成av人片不卡无码久久|