回复 2# 的帖子
private void txtUserID_TextChanged(object sender, EventArgs e)
{
if (txtUserID.Text.Length > 0)
{
if (Encoding.Default.GetByteCount (txtUserID.Text) > 20)
{
int selIndex = txtUserID.SelectionStart;
int selLength = txtUserID.SelectionLength;
txtUserID.Text = txtUserID.Text.Substring(0, txtUserID.Text.Length - 1);
if (selIndex > txtUserID.Text.Length)
{
selIndex = txtUserID.Text.Length + 1;
selLength = 0;
}
else
{
if (selLength > txtUserID.Text.Length - selIndex)
{
selLength = txtUserID.Text.Length - selIndex;
}
}
txtUserID.SelectionStart = selIndex;
txtUserID.SelectionLength = selLength;
}
}
}
是像这样么?但再具体、苛刻点设置怎么办?VS2005的C#操作WinForm