Solved

Calculator C# program simple one have a issue

Posted on 2011-03-09
4
628 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now