简体   繁体   中英

How to write custom “textChanged” function in c#?

This is a code for a single textbox textChanged function. But I want to write a code for common textChanged. I have many textbox named like tbL1InterSR, tbL2InterSR........tbL10InterSR.

private void tbL1InterSR_TextChanged(object sender, EventArgs e)
    {
        if (tbHOI.Text.Length > 0)
        {
            if (tbL1InterSR.Text.Length > 0)
            {
                tbL1RL.Text = (Convert.ToSingle(tbHOI.Text) - Convert.ToSingle(tbL1InterSR.Text)).ToString();
            }
        }
    }

I just want to write a common textChanged function.

If i understand your question correctly... You could simply call the same handler for all textboxes changed event.

Also you know who called the function from the sender argument. That way you know which textbox you're dealing with.

Its simple as calling the same function from two different places.

private void TxtBoxChanged(object sender, MouseButtonEventArgs e)
{
    TextBox textBox = (TextBox)sender; // < -- this how u know which txtBox u working with..
    // more code.....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM