Bir form oluştur ve contructor (yapıcı metod)'unu aşağıdaki şekilde değiştir. Forma kaç tane textbox atarsan at hepsi için kontrolü gerçekleştirmiş olacaksın.
public Form1()
{
InitializeComponent();
foreach (Control item in this.Controls)
{
if (item is TextBox)
{
item.TextChanged += (o, e) =>
{
if (string.IsNullOrEmpty(item.Text))
{
return;
}
try
{
if (item.Text.IndexOf('.') != -1)
{
MessageBox.Show("Girdiğiniz sayı geçerli formatta değildir!\nLütfen . (nokta) işareti kullanmayınız!");
return;
}
int sayi = int.Parse(item.Text);
if (sayi > 100 || sayi < 0)
{
MessageBox.Show("Girdiğiniz sayı 0 ile 100 arasında olmalıdır!");
item.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show("Beklenmeyen hata!\n" + ex.ToString());
}
};
}
}
}