• <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 MoveCmdToLast(TextBox txtCmdInput, String selCmd)//把所選中的命令移動(dòng)到最下一行然后顯示在文本框中
              2        {
              3            String txtStr = txtCmdInput.Text;
              4            int start = txtStr.IndexOf(selCmd);
              5
              6            //把選中行或光標(biāo)所在行的命令送到最后一行且光標(biāo)移到第一行
              7            if (selCmd != null && selCmd.Length > 0 && selCmd != "\r\n")
              8            {
              9                String strLeft = txtStr.Remove(start, selCmd.Length);
             10
             11                //處理剩下的字符串,注意把開頭結(jié)尾的"\r\n"找到刪掉
             12
             13                while (strLeft != null && strLeft.Length > 0 && (strLeft[strLeft.Length - 1== '\r' || strLeft[strLeft.Length - 1== '\n'))
             14                {
             15                    strLeft = strLeft.Remove(strLeft.Length - 11);
             16                }

             17
             18                while (strLeft != null && strLeft.Length > 0 && strLeft[0== '\r')
             19                {
             20                    strLeft = strLeft.Remove(02);
             21                }

             22
             23                //處理你取出的當(dāng)前行的字符串若有"\r\n"注意把它去掉
             24                while (selCmd != "" && selCmd.Length > 0 &&
             25                       (selCmd[selCmd.Length - 1== '\r'
             26                       || selCmd[selCmd.Length - 1== '\n'))
             27                {
             28                    selCmd = selCmd.Remove(selCmd.Length - 11);
             29                }

             30
             31                String strNew = strLeft + "\r\n" + selCmd;
             32                //最后前面留一行空格且把鼠標(biāo)定位到此
             33                txtCmdInput.Text = "\r\n" + strNew;
             34            }

             35            else
             36            {
             37                MessageBox.Show("請(qǐng)您不要發(fā)送空命令,謝謝合作!""溫馨提示:");
             38            }

             39        }

             40        private String GetCmd(TextBox txtCmdInput)//取控件里鼠標(biāo)所在行或光標(biāo)所選擇的命令,發(fā)送的命令暫時(shí)寫到文件中
             41        {
             42            string txtStr = txtCmdInput.Text;
             43            string selStr = txtCmdInput.SelectedText;
             44            string selCmd = null;
             45            int start = 0;
             46            if (selStr != null && selStr.Length > 0)
             47            {
             48
             49                int selBegin = txtStr.IndexOf(selStr);
             50                int selEnd = selBegin + selStr.Length - 1;
             51                string subPreStr = txtStr.Substring(0, selBegin);
             52                string subLastStr = txtStr.Substring(selEnd + 1);
             53                string preleft = null;
             54                string lastleft = null;
             55                if (subPreStr.Length > 0 && subPreStr[subPreStr.Length - 1!= '\n')
             56                {
             57                    int nindex = subPreStr.LastIndexOf("\n");
             58                    preleft = subPreStr.Substring(nindex + 1); 
             59                }

             60                if (subLastStr.Length > 0 && subLastStr[0!= '\r')
             61                {
             62                    int rindex = subLastStr.IndexOf("\r");
             63                    if (rindex != -1)
             64                    {
             65                        lastleft = subLastStr.Substring(0, rindex + 2);
             66                    }

             67                    else lastleft = null;
             68                }

             69                else if (subLastStr != null && subLastStr.Length > 0 && subLastStr[0== '\r')
             70                {
             71                    lastleft = "\r\n";
             72                }

             73                selStr = preleft + selStr + lastleft;
             74                start = txtStr.IndexOf(selStr);
             75                selCmd = selStr;
             76            }

             77            else
             78            {
             79                //取光標(biāo)所在行的字符串包括末尾的換行回車符"\r\n"
             80                //string strCmdText = txtCmdInput.Text;
             81                int curInx = txtCmdInput.SelectionStart;       //光標(biāo)所在位置索引
             82                string tmp = txtStr.Substring(0, curInx);  //開始到光標(biāo)處的子串
             83                int n = tmp.LastIndexOf('\n');             //找光標(biāo)所在行的開頭索引start + 1
             84                start = n + 1;
             85                tmp = txtStr.Substring(curInx);//當(dāng)前光標(biāo)所在位置到最后的子串
             86                int end = tmp.IndexOf('\n'); //找該行的末尾索引包括"\r\n"
             87                string curRowText = null;
             88                if (end > 0)
             89                {
             90                    curRowText = txtStr.Substring(start, curInx - start + end + 1);
             91                }

             92                else
             93                {
             94                    curRowText = txtStr.Substring(start);
             95                }

             96                selCmd = curRowText;
             97            }

             98            //MoveCmdToLast(txtStr,selCmd);
             99            //把光標(biāo)所在行的命令寫入文件中
            100            FileStream fs = new FileStream("D:\\file.txt",FileMode.Append,FileAccess.Write);
            101            StreamWriter sw = new StreamWriter(fs);
            102            sw.Flush();
            103            sw.Write(selCmd);
            104            sw.Flush();
            105            sw.Close();
            106            return selCmd;
            107        }
              
            函數(shù)調(diào)用如下:
                    private void txtCmdInput_KeyDown(object sender, KeyEventArgs e)
                    {
                        if (e.KeyCode == Keys.Enter)
                        {
                            e.SuppressKeyPress = true;    / /回車事件已經(jīng)處理完不再響應(yīng)了
                            string str = GetCmd(txtCmdInput);
                            MoveCmdToLast(txtCmdInput, str);
                        }
                    }
            posted on 2008-09-04 10:35 天書 閱讀(4542) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理



            <2008年9月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            无码人妻精品一区二区三区久久| 亚洲熟妇无码另类久久久| 国产精品一区二区久久| 久久久久亚洲AV无码永不| 成人国内精品久久久久一区| 91久久九九无码成人网站| 精品久久人人妻人人做精品| 一级女性全黄久久生活片免费| 无码AV中文字幕久久专区| 国产 亚洲 欧美 另类 久久| 久久精品亚洲AV久久久无码| 国产成人香蕉久久久久| 久久人妻少妇嫩草AV蜜桃| 国产精品无码久久久久| 久久久久无码精品国产| yellow中文字幕久久网| 久久久久无码精品国产| 奇米影视7777久久精品人人爽| 国产69精品久久久久777| 中文字幕无码av激情不卡久久| 99国产欧美久久久精品蜜芽 | 久久经典免费视频| 久久婷婷国产麻豆91天堂| 综合网日日天干夜夜久久| 无码任你躁久久久久久| 91精品观看91久久久久久| 国产91色综合久久免费| 欧美午夜精品久久久久免费视| 午夜精品久久久久成人| 色偷偷88欧美精品久久久| 国产精品热久久毛片| 国产精品美女久久久久av爽 | 国产精品美女久久久网AV| 99久久成人国产精品免费| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 国产精品禁18久久久夂久| 中文精品久久久久人妻不卡| 欧美精品国产综合久久| 97久久国产综合精品女不卡| 无码人妻精品一区二区三区久久久| 7777精品伊人久久久大香线蕉|