C# WinForm 控件光标
1
private void MoveCmdToLast(TextBox txtCmdInput, String selCmd)//把所选中的命令移动到最下一行然后显示在文本框中
2
{
3
String txtStr = txtCmdInput.Text;
4
int start = txtStr.IndexOf(selCmd);
5
6
//把选中行或光标所在行的命令送到最后一行且光标移到第一行
7
if (selCmd != null && selCmd.Length > 0 && selCmd != "\r\n")
8
{
9
String strLeft = txtStr.Remove(start, selCmd.Length);
10
11
//处理剩下的字符串,注意把开头结尾的"\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 - 1, 1);
16
}
17
18
while (strLeft != null && strLeft.Length > 0 && strLeft[0] == '\r')
19
{
20
strLeft = strLeft.Remove(0, 2);
21
}
22
23
//处理你取出的当前行的字符串若有"\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 - 1, 1);
29
}
30
31
String strNew = strLeft + "\r\n" + selCmd;
32
//最后前面留一行空格且把鼠标定位到此
33
txtCmdInput.Text = "\r\n" + strNew;
34
}
35
else
36
{
37
MessageBox.Show("请您不要发送空命令,谢谢合作!", "温馨提示:");
38
}
39
}









浙公网安备 33010602011771号