KeyPress event using textbox C# winform [duplicate]
This question already has an answer here:
Assigning event TextChanged to all textboxes in Form
3 answers
I have lot of textbox in my winform. maybe 20 to 30 textbox.
and I need all texbox have numerical only when typing.
I use keypress event per textbox to handle the numerical only(code below)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
is there possible way to inherit all textboxes in just 1 keypress event?
c# visual-studio winforms keypress
marked as duplicate by mjwills, Community♦ Nov 16 '18 at 3:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Assigning event TextChanged to all textboxes in Form
3 answers
I have lot of textbox in my winform. maybe 20 to 30 textbox.
and I need all texbox have numerical only when typing.
I use keypress event per textbox to handle the numerical only(code below)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
is there possible way to inherit all textboxes in just 1 keypress event?
c# visual-studio winforms keypress
marked as duplicate by mjwills, Community♦ Nov 16 '18 at 3:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35
add a comment |
This question already has an answer here:
Assigning event TextChanged to all textboxes in Form
3 answers
I have lot of textbox in my winform. maybe 20 to 30 textbox.
and I need all texbox have numerical only when typing.
I use keypress event per textbox to handle the numerical only(code below)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
is there possible way to inherit all textboxes in just 1 keypress event?
c# visual-studio winforms keypress
This question already has an answer here:
Assigning event TextChanged to all textboxes in Form
3 answers
I have lot of textbox in my winform. maybe 20 to 30 textbox.
and I need all texbox have numerical only when typing.
I use keypress event per textbox to handle the numerical only(code below)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
is there possible way to inherit all textboxes in just 1 keypress event?
This question already has an answer here:
Assigning event TextChanged to all textboxes in Form
3 answers
c# visual-studio winforms keypress
c# visual-studio winforms keypress
edited Nov 16 '18 at 3:20
JohnB
1,78311117
1,78311117
asked Nov 16 '18 at 3:17
mr.jmmr.jm
206
206
marked as duplicate by mjwills, Community♦ Nov 16 '18 at 3:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by mjwills, Community♦ Nov 16 '18 at 3:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35
add a comment |
3
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35
3
3
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35
add a comment |
1 Answer
1
active
oldest
votes
Implement the keypress event for only one textbox.
Then select another text box and go to keypress event and select the method you already implemented.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Implement the keypress event for only one textbox.
Then select another text box and go to keypress event and select the method you already implemented.
add a comment |
Implement the keypress event for only one textbox.
Then select another text box and go to keypress event and select the method you already implemented.
add a comment |
Implement the keypress event for only one textbox.
Then select another text box and go to keypress event and select the method you already implemented.
Implement the keypress event for only one textbox.
Then select another text box and go to keypress event and select the method you already implemented.
answered Nov 16 '18 at 3:44
Gihan Saranga SiriwardhanaGihan Saranga Siriwardhana
604424
604424
add a comment |
add a comment |
3
You alreay have the event, just assign it to all textboxes' 'keypress' event.
– Poul Bak
Nov 16 '18 at 3:22
In VS, select all textboxes, then in property inspector, go to events and select your eventhandler.
– Poul Bak
Nov 16 '18 at 3:23
@PoulBak I already did it all textbox had keypress event. I'm asking if there's possible way for simple coding not apply keypress event to all textbox.
– mr.jm
Nov 16 '18 at 3:31
Do you create the textboxes dynamically?
– Poul Bak
Nov 16 '18 at 3:35