hi friend,
in my project for example one textbox i need to type only numbers not the characters if i type the chars it will show
wat shall i do
my idea is it can be done in textbox_keypress event
can anybody give a solution
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
kiran kumarRank #3,110 · 461 reputationPosted Feb 23, 2010, 9:53 PM EST
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 keypress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsLetter(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("enter numeric value");
}
}
}
}
MARK THE ANSWER IF IT HELPS YOU
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Feb 23, 2010, 11:29 PM EST
Naresh Kodumuri34 reputationPosted Feb 23, 2010, 11:44 PM EST
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
return false;
return true;
}
write this function onkeypress="return isNumberKey(event)"
paul daniel189 reputationPosted Mar 1, 2010, 9:19 PM EST
Dim Counter As Byte
Dim IsNumber As Boolean
IsNumber = False
For Counter = 0 To 9
If Chr$(KeyAscii) = Trim(Counter) Then IsNumber = True
Next
If Not IsNumber Then MsgBox ("That is not a number.")
End Sub