C# GUI: How to Build a Desktop App With Windows Forms and WPF
TL;DR: A C# GUI is a desktop interface built in C# on .NET. Windows Forms is the easiest place to start, and WPF suits richer Windows apps. For macOS, Linux, or mobile, use .NET MAUI or Avalonia.

C# is one of the most productive languages for building desktop applications. Visual Studio lets you drag controls onto a window, set their properties, and connect them to C# code in minutes, which is why so many internal business tools, utilities, and data-entry apps are built this way.

This C Sharp GUI tutorial starts with what a GUI is and how the main .NET frameworks compare. You'll then build a sign-up form step by step in Windows Forms, learn how event handling works, and see the same form rebuilt in WPF.

What Is a C# GUI?

A GUI (graphical user interface) lets people interact with software through visual elements such as windows, buttons, menus, and text fields instead of typed commands. A C# GUI is simply a GUI built with the C# language and a .NET UI framework.

GUI programs are event-driven. Instead of running from top to bottom and exiting, the app starts, shows a window, and then waits. When the user clicks a button, types in a box, or ticks a checkbox, the framework raises an event, and your C# code runs in response. Most of the work in C# GUI programming is writing these event handlers.

So, can you use C# for GUI development? Yes. It's one of the strongest options for Windows desktop apps, and with the right framework it can target macOS, Linux, and mobile too.

AI-Powered Full Stack Developer ProgramExplore Program
Here's How to Land a Top Software Developer Job

C# GUI Frameworks Compared

There isn't just one way to build a C# GUI. These are the main frameworks in use today:

Framework

Platforms

How you define the UI

Best for

Windows Forms (WinForms)

Windows

Drag-and-drop designer that generates C# code

Business tools, data-entry apps, fast prototypes, beginners

WPF

Windows

XAML markup plus C#

Rich Windows apps with custom styling, data binding, and MVVM

WinUI 3

Windows 10 and 11

XAML plus C#

Modern Windows apps using the Fluent design system

.NET MAUI

Windows, macOS, iOS, Android

XAML plus C#

One codebase for desktop and mobile (no official Linux support)

Avalonia

Windows, macOS, Linux, iOS, Android, WebAssembly

XAML-style markup plus C#

Cross-platform desktop apps, including Linux

Windows Forms, WPF, WinUI 3, and .NET MAUI come from Microsoft. Avalonia is an open-source framework maintained by a separate team, with a syntax that will feel familiar to WPF developers.

Which C# GUI Framework Should You Choose?

  • You're a beginner, or you need a Windows tool quickly: Choose Windows Forms. It has the gentlest learning curve, and the designer does much of the work.
  • You're building a polished Windows app with custom styling: Choose WPF. It takes longer to learn, but it scales better for complex interfaces.
  • You want the newest Windows look and APIs: Consider WinUI 3.
  • You need desktop and mobile from one codebase: Choose .NET MAUI.
  • You need Linux support: Choose Avalonia.

The rest of this guide uses Windows Forms, the easiest place to learn the core ideas, and then shows the same app in WPF. Events, controls, and properties work similarly across every framework.

AI-Powered Full Stack Developer ProgramExplore Program
Want a Top Software Development Job? Start Here!

How to Create a GUI in C# With Windows Forms

You'll need Visual Studio 2022 or later on Windows, with the .NET desktop development workload installed. The free Community edition works.

  1. Open Visual Studio and select Create a new project.
  2. Search for Windows Forms App and choose the C# version. Pick the template without "(.NET Framework)" in its name. That older template targets the legacy .NET Framework, while the current one targets modern .NET.
  3. Name the project, for example, GUIDemo, and select Next.
  4. Choose the latest Long-Term Support (LTS) version of .NET from the list, then select Create.

Visual Studio opens a blank form, Form1, in the designer. Press F5 to run it, and you'll see an empty window: your first C# GUI application.

If you prefer the command line, the .NET SDK can create and run the same project on Windows:

dotnet new winforms -n GUIDemo
cd GUIDemo
dotnet run

Inside a Windows Forms Project

A new project contains three files worth knowing:

File

What it does

Should you edit it?

Program.cs

The entry point. Starts the app and opens the first form

Rarely

Form1.cs

Your code: event handlers and logic for the form

Yes, this is where you work

Form1.Designer.cs

Code generated by the designer to create and position controls

No, the designer rewrites it

Here's the Program.cs that the template creates:

namespace GUIDemo
{
    internal static class Program
    {
        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();
            Application.Run(new Form1());
        }
    }
}

ApplicationConfiguration.Initialize() applies default settings such as visual styles and high-DPI handling. Application.Run() shows the form and keeps the app running until the form closes.

Learn 45+ in-demand full-stack development skills and tools, including Frontend Development, Backend Development, Version Control and Collaboration, Database Management, and AI-Assisted Development, with our Full Stack Developer Course.

Common C# GUI Controls

You'll find all of these in the Visual Studio Toolbox.

Control

What it's for

Key property

Common event

Label

Displays text the user can't edit

Text

Rarely handled

TextBox

Single-line or multi-line text input

Text, UseSystemPasswordChar, Multiline

TextChanged

Button

Triggers an action

Text, Enabled

Click

CheckBox

An on/off choice

Checked

CheckedChanged

RadioButton

One choice from a group

Checked

CheckedChanged

GroupBox / Panel

Groups related controls and separates radio button sets

Text

Rarely handled

ComboBox

A drop-down list

Items, SelectedItem

SelectedIndexChanged

ListBox

A scrollable list of items

Items, SelectedItems

SelectedIndexChanged

DataGridView

Tabular data, like a spreadsheet

DataSource

CellClick

DateTimePicker

Date and time selection

Value

ValueChanged

PictureBox

Displays an image

Image, SizeMode

Click

MenuStrip

A menu bar

Items

Click on each item

Timer

Runs code at intervals (not visible)

Interval, Enabled

Tick

C# GUI Example: Building a Sign-Up Form

Let's build a sign-up form with a username, a password, two sets of radio buttons, a terms checkbox, and two buttons. Start by changing the form's Text property in the Properties window to "GUI Demo" to set the window title.

Tip: Before writing any code, give every control a descriptive name using the (Name) property, for example, signUpButton instead of button1. Visual Studio uses that name for the control's variable and event handlers, which keeps your code readable.

Step 1: Add a Close Button With a Confirmation Dialog

Drag a Button from the Toolbox onto the form. Set its (Name) to closeButton and its Text to "Close".

C# GUI

Double-click the button. Visual Studio creates a Click event handler in Form1.cs and opens it for you. Add code to ask the user to confirm before closing:

private void closeButton_Click(object? sender, EventArgs e)
{
    DialogResult result = MessageBox.Show("Do you want to close this window?", "Confirm",
        MessageBoxButtons.YesNo, MessageBoxIcon.Question);

    if (result == DialogResult.Yes)
    {
        Close();
    }
}

MessageBox.Show() returns a DialogResult that tells you which button the user pressed, so the window only closes if they choose Yes.

C# GUI

Step 2: Add Labels and Text Boxes

Add two Label controls with the text "Username" and "Password", and two TextBox controls named usernameTextBox and passwordTextBox.

C# GUI

Select passwordTextBox and set its UseSystemPasswordChar property to True. The box now shows dots instead of the characters typed.

C#GUI

Step 3: Add Radio Buttons in Group Boxes

Add a GroupBox with the text "Gender" and place two RadioButton controls inside it, named maleRadioButton and femaleRadioButton.

C# GUI

Radio buttons in the same container act as one group, so selecting one clears the others. To add a second, independent choice, put it in its own container. Add another GroupBox with the text "Payment Method" and two radio buttons, cardRadioButton and netBankingRadioButton. The user can now pick one gender and one payment method.

C# GUI

Step 4: Enable Sign Up Only When the Terms Are Accepted

Add a CheckBox named termsCheckBox with the text "I accept the Terms and Conditions", and a Button named signUpButton with the text "Sign Up".

C# GUI

Double-click the checkbox to create its CheckedChanged handler, which runs every time the box is ticked or cleared:

private void termsCheckBox_CheckedChanged(object? sender, EventArgs e)
{
    signUpButton.Enabled = termsCheckBox.Checked;
}

C# GUI

Then disable the button when the form first opens by adding one line to the constructor in Form1.cs:

public Form1()
{
    InitializeComponent();
    signUpButton.Enabled = false;
}

Step 5: Validate the Input and Create the Account

Double-click signUpButton and add validation so the account is only "created" when every field is filled in correctly. Here is the complete Form1.cs:

namespace GUIDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            signUpButton.Enabled = false;
        }

        private void termsCheckBox_CheckedChanged(object? sender, EventArgs e)
        {
            signUpButton.Enabled = termsCheckBox.Checked;
        }

        private void signUpButton_Click(object? sender, EventArgs e)
        {
            string? error = GetValidationError();
            if (error != null)
            {
                MessageBox.Show(error, "Sign Up", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            MessageBox.Show($"Account created for {usernameTextBox.Text.Trim()}!", "Sign Up",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }

        private void closeButton_Click(object? sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you want to close this window?", "Confirm",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                Close();
            }
        }

        private string? GetValidationError()
        {
            if (string.IsNullOrWhiteSpace(usernameTextBox.Text))
                return "Please enter a username.";

            if (passwordTextBox.Text.Length < 8)
                return "Password must be at least 8 characters long.";

            if (!maleRadioButton.Checked && !femaleRadioButton.Checked)
                return "Please select a gender.";

            if (!cardRadioButton.Checked && !netBankingRadioButton.Checked)
                return "Please select a payment method.";

            return null;
        }
    }
}

Press F5 and try it out. The Sign Up button stays disabled until the terms are accepted, and each missing field produces a specific warning. Once everything is valid, the app confirms the account and closes.

Keeping the checks in a separate GetValidationError() method, rather than inside the click handler, keeps the handler short and makes the rules easy to find and change.

Java Certification TrainingENROLL NOW
Dive Deep Into Java Core Concepts

How Event Handling Works in a C# GUI

When you double-clicked a control in the designer, Visual Studio did two things. It created a handler method in Form1.cs, and it added a line to Form1.Designer.cs that connects the handler to the control's event:

// In Form1.Designer.cs (generated by Visual Studio)
termsCheckBox.CheckedChanged += termsCheckBox_CheckedChanged;
signUpButton.Click += signUpButton_Click;
closeButton.Click += closeButton_Click;

The += operator subscribes a method to an event. When the event fires, every subscribed method runs.

Double-clicking creates a handler for a control's default event, such as Click for a button or CheckedChanged for a checkbox. To handle any other event, select the control, click the Events icon (the lightning bolt) in the Properties window, and double-click the event you want.

Every handler receives two parameters:

  • sender is the control that raised the event.
  • e carries extra details about the event. Many events use the basic EventArgs, while others use a more specific type, such as MouseEventArgs for mouse position.

Because of sender, one handler can serve several controls. For example, if you attach this handler to the CheckedChanged event of both gender radio buttons, the window title shows whichever one was selected:

private void genderRadioButton_CheckedChanged(object? sender, EventArgs e)

private void genderRadioButton_CheckedChanged(object? sender, EventArgs e)
{
    if (sender is RadioButton radio && radio.Checked)
    {
        Text = $"GUI Demo - {radio.Text}";
    }
}

Creating Controls and Events in Code

The designer is optional. You can build the whole interface in C#, which is useful for controls you create at runtime and makes the event wiring easy to see:

namespace HelloGui
{
    public class GreetingForm : Form
    {
        private readonly TextBox nameTextBox = new() { Location = new Point(20, 20), Width = 200 };
        private readonly Button greetButton = new() { Text = "Greet", Location = new Point(230, 18) };
        private readonly Label resultLabel = new() { Location = new Point(20, 60), AutoSize = true };

        public GreetingForm()
        {
            Text = "Hello GUI";
            ClientSize = new Size(330, 110);
            Controls.AddRange(new Control[] { nameTextBox, greetButton, resultLabel });

            greetButton.Click += GreetButton_Click;
        }

        private void GreetButton_Click(object? sender, EventArgs e)
        {
            string name = string.IsNullOrWhiteSpace(nameTextBox.Text) ? "there" : nameTextBox.Text.Trim();
            resultLabel.Text = $"Hello, {name}!";
        }
    }
}

To run it, change the last line of Main in Program.cs to Application.Run(new HelloGui.GreetingForm());. Type a name, click Greet, and the label shows "Hello, " followed by the name. Leave the box empty, and it shows "Hello, there!".

Ready to expand your software development skills? Simplilearn’s Java Course helps you learn Java, Java EE, and service-oriented architecture concepts. Explore the course to build practical knowledge and strengthen your foundation for working with enterprise-level software applications.

Building the Same Form in WPF

WPF separates the layout, written in XAML, from the logic, written in C#. To try it, create a project from the WPF Application template in Visual Studio, or run dotnet new wpf -n GUIDemoWpf.

Here is a simplified version of the sign-up form in MainWindow.xaml:

<Window x:Class="GUIDemoWpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="GUI Demo" Width="360" SizeToContent="Height">
    <StackPanel Margin="20">
        <TextBlock Text="Username" />
        <TextBox x:Name="UsernameTextBox" Margin="0,4,0,12" />

        <TextBlock Text="Password" />
        <PasswordBox x:Name="PasswordInput" Margin="0,4,0,12" />

        <GroupBox Header="Gender" Margin="0,0,0,12">
            <StackPanel Margin="8">
                <RadioButton x:Name="MaleRadioButton" Content="Male" GroupName="Gender" />
                <RadioButton x:Name="FemaleRadioButton" Content="Female" GroupName="Gender" Margin="0,6,0,0" />
            </StackPanel>
        </GroupBox>

        <CheckBox x:Name="TermsCheckBox" Content="I accept the Terms and Conditions" Margin="0,0,0,12" />

        <Button x:Name="SignUpButton" Content="Sign Up" Width="100" HorizontalAlignment="Left"
                IsEnabled="{Binding IsChecked, ElementName=TermsCheckBox}"
                Click="SignUpButton_Click" />
    </StackPanel>
</Window>

And the logic in MainWindow.xaml.cs:

using System.Windows;

namespace GUIDemoWpf
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void SignUpButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(UsernameTextBox.Text) || PasswordInput.Password.Length < 8)
            {
                MessageBox.Show("Enter a username and a password of at least 8 characters.", "Sign Up",
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            MessageBox.Show($"Account created for {UsernameTextBox.Text.Trim()}!", "Sign Up",
                MessageBoxButton.OK, MessageBoxImage.Information);
            Close();
        }
    }
}

Notice the differences from Windows Forms:

  • No code enables the Sign Up button. The IsEnabled="{Binding ...}" line uses data binding to link the button directly to the checkbox, so the button turns on and off by itself.
  • Layout adapts automatically. StackPanel arranges controls vertically, and the window sizes itself to fit (SizeToContent="Height"), with no fixed pixel positions.
  • Passwords use a dedicated control. WPF has a PasswordBox instead of a masked TextBox, and you read its value from the Password property.
  • Similar APIs have slightly different names. WPF's MessageBox takes MessageBoxButton and MessageBoxImage, while Windows Forms uses MessageBoxButtons and MessageBoxIcon.

WinForms vs WPF

Aspect

Windows Forms

WPF

UI definition

Visual designer that generates C# code

XAML markup, with a designer as well

Layout

Mostly fixed positions, with anchoring and docking

Flexible layout panels such as Grid and StackPanel

Data binding

Basic

Powerful and central to how WPF apps are built

Styling

Limited; mostly per-control properties

Styles, templates, and themes for full visual control

Rendering

GDI and GDI+

DirectX, hardware-accelerated

Architecture

Code-behind event handlers

Code-behind or the MVVM pattern

Learning curve

Gentle

Steeper

Best for

Internal tools, forms, quick utilities

Complex, visually rich Windows apps

Which is easier, WinForms or WPF? Windows Forms. You can build a working app without learning a markup language or new patterns. WPF pays off as an app grows, because data binding and styles cut down on repetitive code. Many developers learn WinForms first and move to WPF when their interfaces become more complex.

C# GUI Project Ideas for Beginners

  • Calculator: Buttons, a display TextBox, and click handlers for each operation.
  • To-do list: Add, remove, and mark tasks using a TextBox, a ListBox, and buttons.
  • Unit converter: A ComboBox for units and TextChanged events for live conversion.
  • Stopwatch: Practice the Timer control and its Tick event.
  • Notepad clone: A multi-line TextBox, a MenuStrip, and file open and save dialogs.
  • Image viewer: A PictureBox, an OpenFileDialog, and zoom options.
  • Student records manager: A DataGridView bound to a list, with add, edit, and delete forms.

Start with the calculator or to-do list, then move to the records manager once you're comfortable with events and controls.

The step-by-step Software Engineer Roadmap is designed for professionals seeking to understand the full scope of the profession. Explore the skills, tools, salary potential, and career roadmap needed to build a successful career as a software engineer.

Key Takeaways

  • A C# GUI is built with a .NET UI framework and runs on events, such as clicks and text changes, that trigger your C# code.
  • Windows Forms is the easiest framework to start with, and WPF offers richer layout, styling, and data binding for Windows apps.
  • .NET MAUI and Avalonia take C# GUIs beyond Windows, and Avalonia is the option that supports Linux.
  • Visual Studio's designer creates event handlers when you double-click a control and connects them with the += operator in the designer file.
  • New projects should use the current "Windows Forms App" template on modern .NET, not the legacy .NET Framework template.

Conclusion

Building a C Sharp GUI comes down to three skills: placing controls, setting their properties, and responding to their events. Windows Forms lets you practice all three with very little setup, and the same ideas carry over to WPF, MAUI, and Avalonia when your apps need more.

Once you're comfortable building desktop interfaces, the next step is to expand your software development skills across web applications, APIs, databases, and modern development tools. Our Full Stack Developer Course can help you build these skills while learning how AI is being used across the software development lifecycle.

You can also explore Simplilearn’s Software Development courses to build broader programming and software engineering skills for real-world development. 

FAQs

1. Is Windows Forms deprecated?

No. Windows Forms is open source and supported on current versions of .NET, and Microsoft continues to maintain it. It isn't the newest Windows UI framework, but it remains a practical, supported choice for many desktop apps.

2. Can I build a C# GUI in Visual Studio Code?

You can write and run Windows Forms and WPF apps in Visual Studio Code with the .NET SDK, using dotnet new winforms or dotnet new wpf and dotnet run. However, VS Code doesn't include the drag-and-drop Windows Forms designer so you would lay out controls in code. For designer-based work, use Visual Studio on Windows.

3. Can I convert a Windows Forms app to WPF?

There is no automatic converter, because the two frameworks define interfaces in completely different ways. In practice, you rebuild the screens in XAML and reuse the non-UI code, such as business logic and data access. Keeping logic out of event handlers from the start makes this much easier.

4. How do I move an old .NET Framework WinForms app to modern .NET?

Microsoft publishes a migration guide for moving Windows Forms apps from .NET Framework to modern .NET, and the .NET Upgrade Assistant can automate much of the project conversion. Most standard controls and code carry over, but third-party control libraries and some older APIs may need updates.

5. Is C# better than Python for desktop GUIs?

It depends on the target. C# with Windows Forms or WPF offers a visual designer, strong tooling, and native-feeling Windows apps. Python frameworks such as Tkinter and PyQt are quick to script and cross-platform by default. For Windows-focused business apps, C# is usually the more productive choice.

About the Author

Vaibhav KhandelwalVaibhav Khandelwal

Vaibhav Khandelwal is a proactive tech geek who's always on the edge of learning new technologies. He is well versed in competitive programming and possesses sound knowledge of web development. He likes to read fictional and sci-fi novels and likes to play strategy games like chess

View More
  • Acknowledgement
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.
  • *All trademarks are the property of their respective owners and their inclusion does not imply endorsement or affiliation.
  • Career Impact Results vary based on experience and numerous factors.