private void TextBoxPassword_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { String str = TextBoxPassword.Text.Trim(); if (str.Length > 18) { TextBoxPassword.Text = str.Remove(18); MessageBox.Show("用户名长度不能超过18个字符!", "操作提示"); TextBoxPassword.Select(str.Length, 0); } }