[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Calculator C# program simple one have a issue

Posted on 2011-03-09
4
Medium Priority
?
635 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

649 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