Seach

how to create a custom control text box that accept only numeric values

1.file ->new ->project ->windows form control libary

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace numerical_tbox
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

private void key_press(object sender, KeyPressEventArgs e)//key press event
{
if ((Char.IsNumber(e.KeyChar) == false)^(e.KeyChar=='\b'))//e is used here e contain all information about which causes the event(here is about keys)
{
e.Handled = true;
}
}


}
}

No comments: