?
Solved

Calculator C# program simple one have a issue

Posted on 2011-03-09
4
Medium Priority
?
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

752 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