1 You can try like that(bind the event to textbox):
- private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar >= 65 && e.KeyChar <= 91) || (e.KeyChar >= 97 && e.KeyChar <= 123))
- {
- if (i && e.KeyChar == 69)
- {
- i = false;
- }
- else if (e.KeyChar!=69)
- {
- e.Handled = true;
- }
- }
- }
1 Hi sai,
Try this code in textbox keypress event.. It will work...
1 Hi , Thanks for reply ,this code is not working under button click event
1 if (textBox1.Text.Length==0 && e.KeyChar==' ')
{
e.Handled = true;
}
else
{
e.Handled = false;
}
try this code. this may helps you. thanks in advance
0 Better to use the TextBox.TextChanged Event.
private void myTextBox_TextChanged(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
YourButton.Enabled = !string.IsNullOrWhiteSpace(tb.Text);
}
}