Results 1 to 10 of 10

Thread: calculater code

  1. #1
    nena5936's Avatar
    nena5936 is offline Senior Member+
    Last Online
    11th February 2013 @ 03:50 PM
    Join Date
    05 Oct 2012
    Age
    35
    Gender
    Female
    Posts
    179
    Threads
    9
    Credits
    0
    Thanked
    9

    Question calculater code



    i need calculater code for c# visual studio 2010 i tried many but not working plz help....also tell some useful websites for c# tutorials n projects.

  2. #2
    irtekaz's Avatar
    irtekaz is offline Senior Member+
    Last Online
    10th June 2013 @ 10:56 AM
    Join Date
    09 Aug 2009
    Location
    India
    Gender
    Male
    Posts
    484
    Threads
    64
    Credits
    950
    Thanked
    64

    Default

    Drag the following controls to the form:

    1 textboxe, 10 buttons:

    Change the textbox text property to 0

    Let's also add 4 labels to the Form:

    Start adding the labels from the left to the right on the form, then change their text property to 0:

    You also should change the visible property of the labels to False. (The 4 labels will hide when you play the calculator)

    Now let's add the code to the 10 buttons.

    Scroll down to Click event and double click on the blank cell:

    Then add the following highlighted code:

    private void button10_Click(object sender, EventArgs e)

    {

    //check if the application need to clear the screen first



    if (textBox1.Text == label2.Text)

    // Hit Clear button: in this case it is button 17 (note that you might see an error because you havent added clear button,

    //just ignore the error for a little bit

    button17.PerformClick();

    //Textbox 1 will display the text of the pressed button:

    Button clickedButton = (Button)sender;

    textBox1.Text = textBox1.Text + clickedButton.Text ;

    }

    Lets add the rest of the 5 math symbols: + - * / = to the form:

    Change their text property to the math symbol like the picture below:

  3. #3
    irtekaz's Avatar
    irtekaz is offline Senior Member+
    Last Online
    10th June 2013 @ 10:56 AM
    Join Date
    09 Aug 2009
    Location
    India
    Gender
    Male
    Posts
    484
    Threads
    64
    Credits
    950
    Thanked
    64

    Default

    Programming the addition button: double click on + button and add the following highlighted code:

    private void button13_Click(object sender, EventArgs e)

    {

    try

    {

    label2.Text = textBox1.Text;

    double operand = Convert.ToDouble(label2.Text);

    label4.Text = "+";

    textBox1.Clear();

    }

    catch (Exception ex)

    {

    }

    }



    Programming the subtraction button: double click on - button and add the following highlighted code:

    private void button14_Click(object sender, EventArgs e)

    {

    try

    {

    label2.Text = textBox1.Text;

    double operand = Convert.ToDouble(label2.Text);

    label4.Text = "-";

    textBox1.Clear();

    }

    catch (Exception ex)

    {

    }

    }


    Programming the multiplication button, double click on the * button and add the following highlighted code:



    private void button15_Click(object sender, EventArgs e)

    {

    try

    {

    label2.Text = textBox1.Text;

    double operand = Convert.ToDouble(label2.Text);

    label4.Text = "*";

    textBox1.Clear();

    }

    catch (Exception ex)

    {

    }

    }


    Programming the division button, double click on the / button and add the following highlighted code:



    private void button16_Click(object sender, EventArgs e)

    {

    try

    {

    label2.Text = textBox1.Text;

    double operand = Convert.ToDouble(label2.Text);

    label4.Text = "/";

    textBox1.Clear();

    }

    catch (Exception ex)

    {

    }

    }


  4. #4
    irtekaz's Avatar
    irtekaz is offline Senior Member+
    Last Online
    10th June 2013 @ 10:56 AM
    Join Date
    09 Aug 2009
    Location
    India
    Gender
    Male
    Posts
    484
    Threads
    64
    Credits
    950
    Thanked
    64

    Default

    Lets now program the equal button: double click on = button and add the following highlighted code:

    private void button12_Click(object sender, EventArgs e)

    {

    try

    {

    double a = Convert.ToDouble(label1.Text);

    double b = Convert.ToDouble(label2.Text);

    double c = Convert.ToDouble(textBox1.Text);

    {

    if (label4.Text == "+")

    {

    a = b + c;

    string d = Convert.ToString(a);

    textBox1.Text = d;

    label2.Text = textBox1.Text;

    }

    else if (label4.Text == "-")

    {

    a = b - c;

    string f = Convert.ToString(a);

    textBox1.Text = f;

    label2.Text = textBox1.Text;

    }

    else if (label4.Text == "*")

    {

    a = b * c;

    string f = Convert.ToString(a);

    textBox1.Text = f;

    label2.Text = textBox1.Text;

    }

    else if (label4.Text == "/")

    {

    a = b / c;

    string f = Convert.ToString(a);

    textBox1.Text = f;

    label2.Text = textBox1.Text;

    }



    }

    }

    catch (Exception ex)

    {



    }





    }

  5. #5
    zahidhussain841 is offline Senior Member+
    Last Online
    27th February 2016 @ 06:52 PM
    Join Date
    20 Mar 2010
    Posts
    31
    Threads
    4
    Credits
    0
    Thanked
    0

    Default

    nice sharing!

  6. #6
    irtekaz's Avatar
    irtekaz is offline Senior Member+
    Last Online
    10th June 2013 @ 10:56 AM
    Join Date
    09 Aug 2009
    Location
    India
    Gender
    Male
    Posts
    484
    Threads
    64
    Credits
    950
    Thanked
    64

    Default

    Lets add the last buttons to the form:

    positive/negative button: +/-
    Exit Button:

    Clear Button

    Decimal Button:


    Programming the Decimal button:

    private void button11_Click(object sender, EventArgs e)

    {



    textBox1.Text = textBox1.Text + ;

    }

    Programming the Positive/Negative button:

    private void button19_Click(object sender, EventArgs e)

    {

    double a = Convert.ToDouble(textBox1.Text);

    a = (-1) * a;

    textBox1.Text = a.ToString();

    }

    Programming the Clear button:

    private void button17_Click(object sender, EventArgs e)

    {

    textBox1.Clear();

    label1.Text = "0";

    label2.Text = "0";

    label3.Text = "0";

    label4.Text = "0";

    }




    Programming the Exit Button:

    private void button18_Click(object sender, EventArgs e)

    {

    Application.Exit();

    }




    Run your application and test the Calculator

    Source: C# Calculator

  7. #7
    nena5936's Avatar
    nena5936 is offline Senior Member+
    Last Online
    11th February 2013 @ 03:50 PM
    Join Date
    05 Oct 2012
    Age
    35
    Gender
    Female
    Posts
    179
    Threads
    9
    Credits
    0
    Thanked
    9

    Default

    thankzzzz alot v nice

  8. #8
    nena5936's Avatar
    nena5936 is offline Senior Member+
    Last Online
    11th February 2013 @ 03:50 PM
    Join Date
    05 Oct 2012
    Age
    35
    Gender
    Female
    Posts
    179
    Threads
    9
    Credits
    0
    Thanked
    9

    Default

    c# learning n tutorials ki koi site bta den plzzzz how v can make a login form in c#

  9. #9
    irtekaz's Avatar
    irtekaz is offline Senior Member+
    Last Online
    10th June 2013 @ 10:56 AM
    Join Date
    09 Aug 2009
    Location
    India
    Gender
    Male
    Posts
    484
    Threads
    64
    Credits
    950
    Thanked
    64

  10. #10
    Join Date
    07 Jan 2011
    Location
    Bruxelles
    Gender
    Male
    Posts
    19,938
    Threads
    1080
    Credits
    172,407
    Thanked
    3333

    Default

    Quote nena5936 said: View Post
    thankzzzz alot v nice

    ایک طرف لمبی لمبی امیدیں
    دوسری طرف کل نفس ذائقۃ الموت

Similar Threads

  1. Nokia Secret Codes And Tricks!!!!!!
    By zaibshah in forum General Mobile Discussion
    Replies: 17
    Last Post: 25th June 2012, 09:05 PM
  2. Nokia Mobile Sets Secret Codes
    By majid786 in forum General Mobile Discussion
    Replies: 16
    Last Post: 24th March 2012, 03:48 PM
  3. all format and unlock codes
    By IT_DOCTOR in forum General Mobile Discussion
    Replies: 30
    Last Post: 29th December 2011, 08:19 PM
  4. Nokia 2170 Secret Codes
    By IT_DOCTOR in forum General Mobile Discussion
    Replies: 3
    Last Post: 24th March 2010, 09:32 AM
  5. all gsm secret code
    By tahseenrajput in forum General Mobile Discussion
    Replies: 13
    Last Post: 15th March 2010, 05:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •