C#.net

Creating a Calculator in WPF with C# – Step-by-Step Tutorial

In this tutorials will teach how to make a calculator using wpf C# application step by step. How to create the calculator in wpf application in best coding practice.

First Step

Declare the variables

string CalTotal;
int num1;
int num2;
string option;
int result;

You have to paste the  below Codes

private void Button1_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "1";
}

private void Button2_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "2";
}

private void Button3_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "3";
}

private void Button4_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "4";
}

private void Button5_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "5";
}

private void Button6_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "6";
}

private void Button7_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "7";
}

private void Button8_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "8";
}

private void Button9_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "9";
}

private void Button0_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Text = txtTotal.Text + "0";
}

private void ButtonPlus_Click(object sender, RoutedEventArgs e)
{
    option = "+";
    num1 = int.Parse(txtTotal.Text);

    txtTotal.Clear();
}

private void ButtonMinus_Click(object sender, RoutedEventArgs e)
{
    option = "-";
    num1 = int.Parse(txtTotal.Text);

    txtTotal.Clear();
}

private void ButtonSub_Click(object sender, RoutedEventArgs e)
{
    option = "*";
    num1 = int.Parse(txtTotal.Text);

    txtTotal.Clear();
}

private void ButtonDiv_Click(object sender, RoutedEventArgs e)
{
    option = "/";
    num1 = int.Parse(txtTotal.Text);

    txtTotal.Clear();
}

private void ButtonClear_Click(object sender, RoutedEventArgs e)
{
    txtTotal.Clear();
    result = (0);
    num1 = (0);
    num2 = (0);
}

private void ButtonEql_Click(object sender, RoutedEventArgs e)
{
    num2 = int.Parse(txtTotal.Text);

    if (option.Equals("+"))
        result = num1 + num2;

    if (option.Equals("-"))
        result = num1 - num2;

    if (option.Equals("*"))
        result = num1 * num2;

    if (option.Equals("/"))
        result = num1 / num2;

    txtTotal.Text = result + "";
}

 

 

admin

Recent Posts

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

4 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

2 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago