textbox 光标位置
宇哥_ 2014-04-24 09:59:49 代码如下,直接搬过去就行,求大神帮忙看下如何让光标显示在文本最后???求代码位置
private void button1_Click(object sender, EventArgs e)
{
#region
string[] strList = textBox1.Text.Replace("\r\n ", "").Split(new string[] { "\r\n" }, StringSplitOptions.None);
StringBuilder sbd = new StringBuilder();
bool flag = true;
for (int i = 0; i < strList.Length; i++)
{
flag = true;
string strL = strList[i];
if (strL != "")
{
while (flag)
{
if (Encoding.Default.GetByteCount(strL) > 14)
{
int lenByte = 0;
string str = "";
for (int j = 0; j < strL.Length; j++)
{
string s = strL.Substring(i, 1);
if (Encoding.Default.GetByteCount(s) == 2)
{
lenByte += 2;
str += s;
}
else
{
lenByte++;
str += s;
}
if (lenByte >= 14)
{
break;
}
}
sbd.Append(strL.Substring(0, str.Length));
sbd.Append("\r\n");
strL = " " + strL.Substring(str.Length, strL.Length - str.Length);
}
else
{
flag = false;
sbd.Append(strL);
sbd.Append("\r\n");
}
}
}
}
textBox1.Text = sbd.ToString();
#endregion
}