WinForms Tutorial: Build Desktop Applications from Scratch (2026)
I wrote my first WinForms application in 2003 — a time tracking tool for a small consulting firm. Two decades later, I still reach for WinForms when I need a quick, data-heavy desktop tool that just works. It is mature, stable, and millions of business applications run on it every day.
Windows Forms is a UI framework for building Windows desktop applications using .NET. It provides a rich set of controls, a visual designer, and an event-driven programming model. Drag and drop your way to a functional UI, wire up events, and bind data sources in minutes.
Creating a WinForms Project and the Designer
Start with a blank form in the designer. The Toolbox lists every control. Drag controls, set properties in the Properties window. The designer generates a .Designer.cs file. Set Form properties like Text, Size, StartPosition. The Load event initializes data.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.Text = "Customer Manager";
this.StartPosition = FormStartPosition.CenterScreen;
this.Load += MainForm_Load;
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadCustomers();
}
}
Working with Controls and Layout
Basic controls: TextBox, ComboBox, CheckBox, RadioButton, DateTimePicker, NumericUpDown. Containers: Panel, GroupBox, TabControl, SplitContainer. DataGridView is the star for data-centric apps. Use Anchor and Dock for layout. TableLayoutPanel and FlowLayoutPanel provide grid and flow arrangement.
var panel = new Panel { Dock = DockStyle.Top, Height = 60 };
var label = new Label { Text = "Customer Name:", Location = new Point(12, 20) };
var textBox = new TextBox { Location = new Point(110, 18), Width = 200 };
var button = new Button { Text = "Search", Location = new Point(320, 17) };
button.Click += (s, e) => SearchCustomers(textBox.Text);
panel.Controls.AddRange(new Control[] { label, textBox, button });
Data Binding with BindingSource and DataSet
BindingSource connects controls to data sources, providing navigation, sorting, filtering. Use simple binding for individual properties and complex binding for DataGridView. BindingNavigator provides a toolbar for record navigation.
var bindingSource = new BindingSource();
bindingSource.DataSource = customerService.GetAll();
grid.DataSource = bindingSource;
var nav = new BindingNavigator(true){Dock=DockStyle.Top,BindingSource=bindingSource};
nameBox.DataBindings.Add("Text", bindingSource, "Name");
Event Handling and Custom Controls
WinForms is event-driven. Wire events in the designer or programmatically. Create custom UserControls by composing existing controls. Add custom properties and events. Custom painting via OnPaint and GDI+ for graphs and custom visuals.
public class AddressControl : UserControl
{
public AddressControl()
{
Controls.Add(new TextBox{Location=new Point(0,0),Width=200});
Controls.Add(new TextBox{Location=new Point(0,30),Width=150});
}
public string Street
{
get => Controls[0].Text;
set => Controls[0].Text = value;
}
}
Working with Dialogs and Multiple Forms
Built-in dialogs: OpenFileDialog, SaveFileDialog, FolderBrowserDialog, ColorDialog. Use ShowDialog() for modal dialogs. MDI (Multiple Document Interface) with IsMdiContainer and MdiParent. Modern apps prefer tabbed interfaces with TabControl.
using var dialog = new OpenFileDialog
{
Filter = "CSV Files|*.csv|All Files|*.*",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
};
if (dialog.ShowDialog() == DialogResult.OK)
{
ImportFromCsv(dialog.FileName);
}
Deployment, ClickOnce, and Modernization
ClickOnce provides self-updating deployment from a URL. MSI installers via setup projects. Embed WebView2 for modern web UI. Add async/await for responsive UIs. MVVM pattern with CommunityToolkit.Mvvm for testability.
WinExe
net8.0-windows
true
Frequently Asked Questions
Is WinForms still supported in .NET 8?
Yes, WinForms is fully supported in .NET 8. Microsoft continues maintenance with high-DPI scaling improvements, accessibility enhancements, and async support.
Should I use WinForms or WPF for a new desktop app?
Use WinForms for rapid development and data-heavy apps. Use WPF for advanced UI customization, complex animations, data templates, and MVVM for large-scale apps.
Can WinForms apps run on Linux or macOS?
No, WinForms depends on Windows GDI+ API. For cross-platform desktop, consider .NET MAUI, Avalonia, or Uno Platform.
How do I handle high-DPI displays in WinForms?
Set Application.SetHighDpiMode to PerMonitorV2, enable AutoScaleMode.Dpi on forms. .NET 8 includes significant high-DPI improvements.
Originally published on Ayodhyyya. Last updated June 1, 2026.