Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calculator C# program simple one have a issue

Posted on 2011-03-09
4
Medium Priority
?
637 Views
Last Modified: 2012-06-27
Hi,

Calculator C# program simple one have a issue

The below code. I want a message like

Sum of a and B : (here the total)
Substraction of a and b: (Here the answer)

Just a message so the label is not seen as we open the calc

Experts please help.

regards
Raja
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        int a,b,c;
    

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a + b;
                   
            label.Text = c.ToString();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a - b;

            label3.Text = c.ToString();

        }
    }
}

Open in new window

0
Comment
Question by:bsharath
  • 2
4 Comments
 
LVL 10

Expert Comment

by:peetm
ID: 35081762
If the textboxes are 'pre-loaded', which it seems they are, and, as you're not interested in sender/e, then you can call the button-click from the form_load:

private void Form1_Load(object sender, EventArgs e)
{
    button1_Click(sender, e)
}
0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 500 total points
ID: 35081767
If the textboxes are 'pre-loaded', which it seems they are, and, as you're not interested in sender/e, then you can call the button-click from the form_load:

private void Form1_Load(object sender, EventArgs e)
{
    button1_Click(sender, e); // <- oops, forgot the ;
}
0
 
LVL 10

Accepted Solution

by:
gavsmith earned 1000 total points
ID: 35081789
Do you mean like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        int a,b,c;
    

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a + b;
                   
            label.Text = "Sum of A and B: " + c.ToString();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a - b;

            label3.Text = "Subtraction of A and B: " + c.ToString();

        }
    }
}

Open in new window


or maybe this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        int a,b,c;
    

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a + b;
                   
            label.Text = "Sum of " + a.ToString() + " and " b.ToString() + ": " + c.ToString();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a - b;

            label3.Text = "Subtraction of " + a.ToString() + " and " b.ToString() + ": " + c.ToString();
        }
    }
}

Open in new window


Please let me know if I'm misunderstanding your question.

HTH
Gav
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 500 total points
ID: 35081807
Do you want some kind of messagebox ?


private void button1_Click(object sender, EventArgs e)
        {

            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a + b;
                   
            label.Text = c.ToString();
           MessageBox.Show(this, "Sum of " + textBox1.Text +" and " + textBox2.Text + " : " + c.ToString() ;
       }

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question