 
 
TextBox a Sadece Sayı Girebilme
Bu örnekte textBox nesnesine sadece sayı girişi yapılacak. String girilemiyecek. String girilmeye çalışıldığında bizi uyaracak. textBox ın KeyPress olayına aşağıdaki kodları yazacağız. Public Form1()
kısmına textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox1_KeyPress);
i eklemeyi unutmayın.        
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox1_KeyPress);
        }
        
        private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if ((e.KeyChar) == 8)
            {
         e.Handled = false;
         return; 
     }
     if ((e.KeyChar) < 48 | (e.KeyChar) > 57) 
            {
         e.Handled = true;
         MessageBox.Show("Sadece Sayı Girebilirsiniz", "Dikkat!!", MessageBoxButtons.OK);
         return; 
     }
        }
    }
}
//Bir sonraki makalede görüşmek üzere. Bahadır