Solved

Calculator C# program simple one have a issue

Posted on 2011-03-09
4
631 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 125 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 250 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 125 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 63
Powershell  and PSExec = Password failure 5 24
tableview is not updating 1 22
Need a simple RegEx to search for two words 27 47
This article will show, step by step, how to integrate R code into a R Sweave document
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 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