Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir

i want to know how to add two nos. in gui...if i havee one textbox1 and textbox2 and i have to add the values in both the text and want to show the result in third text box....textbox3...on clicking on click button


i m facing prblm plz help me.........
Posted

SHALU DIXIT wrote:
i m facing prblm plz help me.........

What problem you are facing?

As per what it seems, you are trying to append texts of two textboxes and show it in third. You can use various events for the same. Use textchange event of the textboxes to do the operation of adding up and then displaying it in third.
 
Share this answer
 
Here is answer -

public button_click()
{
TextBox3.Text = Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text);
}

Regards,

Nilesh Shah.
 
Share this answer
 
Comments
Johnny J. 25-May-10 5:11am    
I think you're missing a ToString() here....
Hello Shanlu,

i have used C# to solve your query because u didn't mention any tags like C# or VB.NET or something anyways hers your code as per your requirement...

I feel you are a beginner so grab a good book for C# and start coding,
i have first converted the text entered into integer value and then added them displaying their result at third textbox


private void button1_Click(object sender, EventArgs e)
        {
            //i have used try catch so that if the user tries characters a message will be displayed
            try
            {
                // adding two numbers here
               int x= int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
                // display result in 3rd textbox
               textBox3.Text = x.ToString(); // integer is casted to string
            }
            catch (Exception ex)
            {
//show messagebox
                MessageBox.Show("Invalid text format for addition");
                //clear the textboxes
                textBox1.Clear();
                textBox2.Clear();
            }
        }


Now if you want that in your textboxes only number must be entered then you can refer to one of my answers here
Numeric Textbox by Radix

Do rate my answer once you find it useful
Thanks & Regards
Radix :rose:
 
Share this answer
 
v2

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