プロが教えるわが家の防犯対策術!

C#で最大文字数以上の入力をした場合は再度入力をお願いするプログラムを組むにはどうしたらよいでしょうか?

A 回答 (1件)

private void textBox1_KeyUp(object sender, KeyEventArgs e)


{
int len = textBox1.TextLength;
if (len > 10)
{
MessageBox.Show("入力文字数が多すぎます。");
//textBox1..Undo();
textBox1.Text = textBox1.Text.Remove(len-1);
textBox1.SelectionStart = len-1;
textBox1.SelectionLength = 0;
}
}
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!