winforms
Windows Forms is a .NET UI framework for building Windows desktop applications.
Top Related Projects
Mono open source ECMA CLI, C# and .NET implementation.
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
Cross platform GUI framework for desktop and mobile applications in .NET
Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
Quick Overview
The dotnet/winforms repository is the home for Windows Forms (WinForms) on .NET Core and .NET 5+. It's an open-source framework for building Windows desktop applications with a graphical user interface. WinForms provides a set of controls and tools for creating rich, responsive, and user-friendly applications.
Pros
- Cross-platform development: Can be developed on Windows, macOS, or Linux
- Familiar and easy-to-use API for Windows developers
- Extensive set of pre-built controls and components
- Seamless integration with other .NET technologies
Cons
- Limited to Windows for deployment and runtime
- Older technology compared to more modern UI frameworks
- Less flexibility in UI design compared to web-based alternatives
- Performance can be slower than native Windows applications
Code Examples
- Creating a simple form with a button:
using System.Windows.Forms;
public class MainForm : Form
{
public MainForm()
{
Text = "Hello, WinForms!";
var button = new Button
{
Text = "Click me!",
Location = new System.Drawing.Point(10, 10)
};
button.Click += (sender, e) => MessageBox.Show("Button clicked!");
Controls.Add(button);
}
}
- Handling events:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Button was clicked!";
}
- Data binding:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
// In your form:
var person = new Person { Name = "John Doe", Age = 30 };
textBox1.DataBindings.Add("Text", person, "Name");
numericUpDown1.DataBindings.Add("Value", person, "Age");
Getting Started
- Install the .NET SDK from https://dotnet.microsoft.com/download
- Create a new WinForms project:
dotnet new winforms -n MyWinFormsApp cd MyWinFormsApp
- Open the project in your preferred IDE (e.g., Visual Studio, VS Code)
- Edit the Form1.cs file to add controls and logic
- Run the application:
dotnet run
Competitor Comparisons
Mono open source ECMA CLI, C# and .NET implementation.
Pros of mono
- Broader platform support, including Linux and macOS
- Includes a complete runtime and class libraries, not just UI components
- Longer history and more established community
Cons of mono
- Generally slower performance compared to .NET Core
- Less frequent updates and potentially outdated components
- Larger codebase to maintain and navigate
Code Comparison
mono:
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
winforms:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Label label = new Label();
label.Text = "Hello World!";
this.Controls.Add(label);
}
}
The mono example shows a basic console application, while the winforms example demonstrates creating a simple GUI form with a label. This highlights the different focus of each project: mono as a complete runtime and winforms as a specific UI framework.
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
Pros of Avalonia
- Cross-platform support (Windows, macOS, Linux, Web)
- Modern, XAML-based UI framework with reactive extensions
- Active development and growing community
Cons of Avalonia
- Smaller ecosystem and fewer third-party controls compared to WinForms
- Steeper learning curve for developers familiar with traditional Windows Forms
Code Comparison
Avalonia:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button Content="Click me!" />
</Window>
WinForms:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Button button1 = new Button();
button1.Text = "Click me!";
this.Controls.Add(button1);
}
}
Summary
Avalonia offers a modern, cross-platform approach to UI development, making it suitable for projects targeting multiple operating systems. It uses XAML for UI design, which can be more expressive and maintainable than WinForms' code-behind approach. However, WinForms has a larger ecosystem and may be more familiar to Windows-centric developers. The choice between the two depends on project requirements, target platforms, and developer expertise.
Cross platform GUI framework for desktop and mobile applications in .NET
Pros of Eto
- Cross-platform support (Windows, macOS, Linux)
- Native look and feel on each platform
- Single codebase for multiple platforms
Cons of Eto
- Smaller community and less documentation
- Fewer built-in controls compared to WinForms
Code Comparison
Eto:
var button = new Button { Text = "Click Me" };
button.Click += (sender, e) => MessageBox.Show("Hello, Eto!");
Content = button;
WinForms:
var button = new Button { Text = "Click Me" };
button.Click += (sender, e) => MessageBox.Show("Hello, WinForms!");
Controls.Add(button);
Summary
Eto offers cross-platform development with a native look and feel, making it suitable for projects targeting multiple operating systems. However, it has a smaller community and fewer built-in controls compared to WinForms. WinForms, being a mature framework, provides extensive documentation and a wide range of controls but is limited to Windows.
The code comparison shows that both frameworks have similar syntax for creating and handling UI elements, with minor differences in how controls are added to the form or window.
Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
Pros of Xamarin.Forms
- Cross-platform development for iOS, Android, and Windows
- Single codebase for multiple platforms, reducing development time
- Rich UI controls and layouts for mobile app development
Cons of Xamarin.Forms
- Steeper learning curve compared to WinForms
- Performance can be slower than native development
- Limited access to platform-specific features without custom renderers
Code Comparison
Xamarin.Forms:
public class MainPage : ContentPage
{
public MainPage()
{
Content = new StackLayout
{
Children = {
new Label { Text = "Welcome to Xamarin.Forms!" }
}
};
}
}
WinForms:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Label label = new Label();
label.Text = "Welcome to WinForms!";
this.Controls.Add(label);
}
}
The code comparison shows the different approaches to creating a simple UI with a label. Xamarin.Forms uses a more declarative style with XAML-like syntax, while WinForms uses a more imperative approach with direct manipulation of controls.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Windows Forms
Windows Forms (WinForms) is a UI framework for building Windows desktop applications. It is a .NET wrapper over Windows user interface libraries, such as User32 and GDI+. It also offers controls and other functionality that is unique to Windows Forms.
Windows Forms also provides one of the most productive ways to create desktop applications based on the visual designer provided in Visual Studio. It enables drag-and-drop of visual controls and other similar functionality that make it easy to build desktop applications.
Windows Forms Out-Of-Process Designer
For information about the WinForms Designer supporting the .NET runtime and the changes between the .NET Framework Designer (supporting .NET Framework up to version 4.8.1) vs. the .NET Designer (supporting .NET 6, 7, 8, 9+), please see Windows Forms Designer Documentation.
Important: As a Third Party Control Vendor, when you migrate controls from .NET Framework to .NET, your control libraries at runtime are expected to work as before in the context of the respective new TFM (special modernization or security changes in the TFM kept aside, but those are rare breaking changes). Depending on the richness of your control's design-time support, the migration of control designers from .NET Framework to .NET might need to take a series of areas with breaking changes into account. The provided link points out additional resources which help in that migration process.
Relationship to .NET Framework
This codebase is a fork of the Windows Forms code in the .NET Framework 4.8. We started the migration process by targeting .NET Core 3.0, when we've strived to bring the two runtimes to a parity. Since then, we've done a number of changes, including breaking changes, which diverged the two. For more information about breaking changes, see the Porting guide.
The bar for innovation and new features
WinForms is a technology which was originally introduced as a part of .NET Framework 1.0 on February 13th, 2002. It's primary focus was and is to be a Rapid Application Tool for Windows based Apps, and that principal sentiment has not changed over the years. WinForms at the time addressed developer's requests for
- A framework for stable, monolithic Line of Business Apps, even with extremely complicated and complex domain-specific workflows
- The ability to easily provide rich user interfaces
- A safe and - over the first 3 versions of .NET Framework - increasingly performant way to communicate across process boundaries via various Windows Communication Services, or access on-site databases via ADO.NET providers.
- A very easy to use, visual what-you-see-is-what-you-get designer, which requires little ramp-up time, and was primarily focused to support 96 DPI resolution-based, pixel-coordinated drag & drop design strategies.
- A flexible, .NET reflection-based Designer extensibility model, utilizing the .NET Component Model.
- Visual Controls and Components, which provide their own design-time functionality through Control Designers
Over time, and with a growing need to address working scenarios with multi-monitor, high resolution monitors, significantly more powerful hardware, and much more, WinForms has continued to be modernized.
And then there is the evolution of Windows: When new versions of Windows introduce new or change existing APIs or technologies - WinForms needs to keep up and adjust their APIs accordingly.
And exactly that is still the primary motivation for once to modernize and innovate, but also the bar to reach for potential innovation areas we either need or want to consider:
- Areas, where for example for security concerns, the Windows team needed to take an depending area out-of-proc, and we see and extreme performance hit in WinForms Apps running under a new Service Pack or a new Windows Version
- New features to comply with updated industry standards for accessibility.
- HighDPI and per Monitor V2-Scenarios.
- Picking up changed or extended Win32 Control functionality, to keep controls in WinForms working the way the Windows team wants them to be used.
- Addressing Performance and Security issues
- Introducing ways to support asynchronous calls interatively, to enable apps to pick up migration paths via Windows APIs projection/Windows Desktop Bridge, enable scenarios for async WebAPI, SignalR, Azure Function, etc. calls, so WinForms backends can modernized and even migrated to the cloud.
What would not make the bar:
- New functionality which modern Desktop UIs like WPF or WinUI clearly have already
- Functionality, which would "stretch" a Windows Desktop App to be a mobile, Multi-Media or IoT app.
- Domain-specific custom controls, which are already provided by the vast variety of third party control vendors
A note about Visual Basic: Visual Basic .NET developers make up about 20% of WinForms developers. We welcome changes that are specific to VB if they address a bug in a customer-facing scenario. Issues and PRs should describe the customer-facing scenario and, if possible, include images showing the problem before and after the proposed changes. Due to limited bandwidth, we cannot prioritize VB-specific changes that are solely for correctness or code cleanliness. However, VB remains important to us, and we aim to fix any critical issues that arise.
Please note
:warning: This repository contains only implementations for Windows Forms for .NET platform.
It does not contain either:
- The .NET Framework variant of Windows Forms. Issues with .NET Framework, including Windows Forms, should be filed on the Developer Community or Product Support websites. They should not be filed on this repository.
- The Windows Forms Designer implementations. Issues with the Designer can be filed via VS Feedback tool (top right-hand side icon in Visual Studio) or be filed in this repo using the Windows Forms out-of-process designer issue template.
How can I contribute?
We welcome contributions! Many people all over the world have helped make this project better.
- Contributing explains what kinds of changes we welcome
- Developer Guide explains how to build and test
- Get Up and Running with Windows Forms .NET explains how to get started building Windows Forms applications.
How to Engage, Contribute, and Provide Feedback
Some of the best ways to contribute are to try things out, file bugs, join in design conversations, and fix issues.
- The contributing guidelines and the more general .NET contributing guide define contributing rules.
- The Developer Guide defines the setup and workflow for working on this repository.
- If you have a question or have found a bug, file an issue.
- Use daily builds if you want to contribute and stay up to date with the team.
Reporting security issues
Security issues and bugs should be reported privately via email to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter. Also see info about related Microsoft .NET Core and ASP.NET Core Bug Bounty Program.
Code of Conduct
This project uses the .NET Foundation Code of Conduct to define expected conduct in our community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at conduct@dotnetfoundation.org.
License
.NET (including the Windows Forms repository) is licensed under the MIT license.
.NET Foundation
.NET Windows Forms is a .NET Foundation project.
See the .NET home repository to find other .NET-related projects.
Top Related Projects
Mono open source ECMA CLI, C# and .NET implementation.
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
Cross platform GUI framework for desktop and mobile applications in .NET
Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot