Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have look over the net but cant find an answer to a simple question. I have 3 textboxs
for math TB1 12 * TB2 12 = TB3 (144). when I type the numbers into text 1 and 2 I want it to show in textbox3 without Buttons.

any links would be helpful

Thanks

What I have tried:

C#
int res = 0;
           try
           {
               res = Convert.ToInt32(tbLength.Text) * Convert.ToInt32(tbWidth.Text);
               textBox2.Text = res.ToString();
           }
           catch (Exception ) { }
Posted
Updated 29-Jan-17 6:19am
v2
Comments
[no name] 28-Jan-17 20:13pm    
The simple answer to your simple question is use the text changed event.

Just handle the text change event. Inside that do your calculations and show in another textbox.
 
Share this answer
 
As the others already stated, you can use the TextChanged event of the textboxes.
Here's an (WinForms) example of how to do that:
C#
public Form1()
{
    InitializeComponent();

    tbWidth.TextChanged += tbWidthLength_TextChanged;
    tbLength.TextChanged += tbWidthLength_TextChanged;
}

private void tbWidthLength_TextChanged(object sender, EventArgs e)
{
    int width, length;

    int.TryParse(tbWidth.Text, out width);
    int.TryParse(tbLength.Text, out length);

    textBox2.Text = (width * length).ToString();
}
Peter
 
Share this answer
 
try
{
decimal Length= = Convert.ToDecimal(tbLength.Text);
decimal Width= = Convert.ToDecimal(tbWidth.Text);

decimal res = Length * Width;
textBox2.Text = res.ToString();
}
catch (Exception )
{ }
 
Share this answer
 
v2
Thanks Guys That help me a lot.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900