I´m doing simple program in WPF C# and I have many TextBoxes
- each TextBox
do same thing and I´m very lazy to write each Event for each TextBox
.
So, Is there any way how to serve all TextBox
by one Event?
There is a short code:
private void OnMouseLeft(object sender, MouseButtonEventArgs e)
{
TextBox1.Text = string.Empty;
TextBox1.Foreground = Brushes.Black;
}
private void OnMouseLeft1(object sender, MouseButtonEventArgs e)
{
TextBox2.Text = string.Empty;
TextBox2.Foreground = Brushes.Black;
}
Thank You! :)
The 'sender' parameter will be the TextBox itself. So just write one function and attach them all to that one function.
Attach same handler to all textboxes and use
sender
argument to get textbox instance which raised event:try this for all textbox not allowed numeric value only text..
$('input[type=text]') .keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) { e.preventDefault(); } else { var key = e.keyCode; if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) { e.preventDefault(); } } });
Add each taxBox to the same method and then get the TextBox clicked as shown, I did not this but it should work or at least get you going in the right direction. I hop it helps.
You can use sender