Try This:-
First set the MaxLength Property of Textbox to 2 and then write following the following code:-
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (textBox1.Text.Length > 2)
{
MessageBox.Show("Can Enter only two Characters in this Textbox.", "Textbox", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}