C# Exercises

Home AgriMetSoft About Contact

How to make a C# Textbox Accepts Only Numbers Or Characters

	
namespace Textbox_just_Numbers
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void just_number_KeyPress(object sender, KeyPressEventArgs e)
    {
      if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
      {
        e.Handled = true;
      }
    }

    private void just_char_KeyPress(object sender, KeyPressEventArgs e)
    {
      if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
      {
        e.Handled = true;
      }
    }

    private void char_numbers_KeyPress(object sender, KeyPressEventArgs e)
    {
      if (!char.IsControl(e.KeyChar) && !char.IsLetterOrDigit(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
      {
        e.Handled = true;
      }
    }
  }
}

	


Download the project of Visual Studio 2013 in DropBox Download


How to use a TextBox enter Just Numbers or Just Characters | TextBox which accepts only Letters


List of Exercises