Beginner desktop tutorial

Build your first C# calculator with Windows Forms

Learn the foundations of desktop programming by creating a working calculator in C#. This hands-on lesson shows you how to place controls on a form, respond to button clicks, process user input, and display results in a real Windows application.

Why a calculator is a great first C# project

A calculator is one of the best starter projects for C# beginners because it is simple to understand but still teaches the building blocks of real software. You work with forms, buttons, text input, variables, arithmetic, and output, all inside one compact project.

Windows Forms is especially useful for beginners because you can see the interface as you build it. Instead of learning only from console examples, you create something visual and interactive from the start.

What you will learn

  • How to create a Windows Forms project in Visual Studio 2026
  • How to place TextBox, Button, and Label controls on a form
  • How button click events work in C#
  • How to read numeric input, calculate a result, and display it clearly
  • How to improve a beginner project with validation and better usability

Step-by-step tutorial

1. Create the project

Open Visual Studio 2026 and create a new Windows Forms App using C#. Name the project SimpleCalculator. After the project loads, you will see a blank form that will become your calculator window.

2. Add the controls

Place the following controls on the form:

  • Two TextBox controls for number entry
  • Four Button controls for Add, Subtract, Multiply, and Divide
  • One Label control to display the result

Suggested control names: txtNum1, txtNum2, btnAdd, btnSubtract, btnMultiply, btnDivide, and lblResult.

3. Write the code

Double-click each button in the designer to create its click event, then add code like this:

private void btnAdd_Click(object sender, EventArgs e)
{
    double num1 = Convert.ToDouble(txtNum1.Text);
    double num2 = Convert.ToDouble(txtNum2.Text);
    double result = num1 + num2;
    lblResult.Text = "Result: " + result.ToString();
}

private void btnSubtract_Click(object sender, EventArgs e)
{
    double num1 = Convert.ToDouble(txtNum1.Text);
    double num2 = Convert.ToDouble(txtNum2.Text);
    double result = num1 - num2;
    lblResult.Text = "Result: " + result.ToString();
}

private void btnMultiply_Click(object sender, EventArgs e)
{
    double num1 = Convert.ToDouble(txtNum1.Text);
    double num2 = Convert.ToDouble(txtNum2.Text);
    double result = num1 * num2;
    lblResult.Text = "Result: " + result.ToString();
}

private void btnDivide_Click(object sender, EventArgs e)
{
    double num1 = Convert.ToDouble(txtNum1.Text);
    double num2 = Convert.ToDouble(txtNum2.Text);

    if (num2 == 0)
    {
        lblResult.Text = "Result: Cannot divide by zero";
        return;
    }

    double result = num1 / num2;
    lblResult.Text = "Result: " + result.ToString();
}

4. Run and test the program

Run the application, enter two numbers, and click each operation button. This helps you see how event-driven desktop applications respond instantly to user actions.

Tip for learners: Test a range of values, including decimal numbers and division by zero. Small experiments like these help you understand how your code behaves in real use.

Easy ways to improve your calculator

Add a Clear button

Let users reset both text boxes and the result label with one click.

Validate input

Use double.TryParse instead of Convert.ToDouble to handle invalid input more safely.

Improve the layout

Add labels, spacing, and consistent button sizes to make the application easier to use.

Best practice: A program should not only work when the user enters perfect input. Adding validation and clear feedback is part of writing professional software.

Build on this project

Once you finish this calculator, the next step is to create a larger desktop application with multiple screens, stored data, and more realistic workflows. That is where business-style projects become especially valuable.

Continue to the inventory management project →

Keep building

Ready for the next desktop project?

Use this calculator as your first step, then move on to larger Windows applications that work with databases, forms, reports, and real business processes.

Related desktop pages

Continue learning with the desktop track