• <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 | 我們學習網
            按回車光標轉向下一控件。  回復  更多評論
              

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

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            99久久无色码中文字幕| 久久久久亚洲av无码专区| 久久99精品久久久久久噜噜| 久久福利片| 久久精品国产亚洲av高清漫画| 国产精品久久影院| 综合久久精品色| 日本一区精品久久久久影院| 久久久久久久综合综合狠狠| 亚洲综合精品香蕉久久网| 久久97精品久久久久久久不卡| 日日狠狠久久偷偷色综合96蜜桃| 亚洲AV无一区二区三区久久 | 久久久久亚洲AV无码网站| 91久久精品视频| 精品熟女少妇a∨免费久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 97香蕉久久夜色精品国产| 四虎国产精品免费久久5151| 亚洲色欲久久久久综合网| 婷婷综合久久狠狠色99h| 久久婷婷五月综合97色 | 99久久综合国产精品免费 | 久久久精品国产免大香伊| 久久精品国产亚洲欧美| 欧美牲交A欧牲交aⅴ久久| 一本色道久久综合| 久久午夜无码鲁丝片午夜精品| 99久久国产主播综合精品| 久久亚洲私人国产精品vA| 久久久久久久久久久精品尤物| 亚洲精品成人网久久久久久| 久久久久国产亚洲AV麻豆| 久久精品国产清自在天天线| 国产巨作麻豆欧美亚洲综合久久| 久久精品国产影库免费看| 久久人妻少妇嫩草AV无码专区| 亚洲精品乱码久久久久久蜜桃图片 | 亚洲精品视频久久久| 久久青青草原精品国产软件| 久久久久无码精品|