The Definitive Guide to WinForms Controls
WinForms (Windows Forms) is the original .NET platform for building desktop applications for Windows PCs. A WinForms application is composed of various code and resource files compiled into a runtime executable. Every part of the WinForms application — including the user interface — is defined by writing extensive C# .NET or VB.NET code — a process made easier using the Visual Studio designer.
WinForms Controls
WinForms UI controls are reusable design elements that help developers implement a wide variety of features. Technically, you can create anything you want in .NET Windows Forms with enough code, but UI controls save you time by providing a collection of commonly used concepts like buttons, text boxes, and so on.
Controls have an API (application programmable interface), which lets you configure how the control will work for your specific application. Consider a Button control, for example. It has a “Text” property, which can be set to the text you want displayed in the button. It also has size properties like “Width” and “Height.” It also has event triggers when actions occur, such as a “Clicked” event that fires when the user clicks the button. Complex controls have richer APIs.
Standard WinForms Controls
The base controls included with .NET are often known as “standard” or “basic” controls. These controls are a part of the base .NET libraries. Standard .NET WinForms controls typically fall into three main categories: input, layout, and data display.
- Input controls are used to collect input from the user or provide text editing.
- Layout controls define the window or frame layout, including containers and toolbars.
- Data controls are used to display and sometimes edit collections of data.
Below is a table containing the common WinForms controls.
This table leaves out some additional non-UI components and dialogs that don’t display on the form but can impact the usability of the application. For complete lists of UI controls, check out the .NET documentation.
The datagrid control is often the heart or brain of the application, providing the most data-centric functionality in one control. Users can view, edit, and analyze their data with one powerful control. The standard datagrid, DataGridView, supports basic functions like data-binding, sorting, cell formatting, column reordering, and selection.
Advanced and niche features can be achieved using a third-party datagrid. These features include exporting to Microsoft Excel, multi-level hierarchical views, transposing the rows and columns, multi-line rows, and so much more. You can save a lot of time by licensing a third-party datagrid library rather than implementing those features yourself — which involves extending the DataGridView and overriding a lot of rendering. Continue reading for more information.
Third-Party WinForms Controls and Components
Microsoft made the .NET frameworks extensible, allowing developers to further extend the capabilities of their applications themselves. Third-party control suites typically fill the gap for input controls, as well as provide new and innovative layout and data-centric controls. Unlike most free control suites, they come with complete samples and documentation and are regularly updated and tested.
You can find some free WinForms controls on GitHub. You can even invest in professionally developed UI controls from companies like DevExpress, Mescius (formerly GrapeCity), Progress (formerly Telerik), and SyncFusion.
Top Five Custom WinForms Controls
We’ve analyzed the install data to see the most downloaded third-party WinForms controls. Just looking at the ComponentOne WinForms controls, which have been developed for over 20 years since .NET 1.0, here are the most popular five controls:
1.FlexGrid — It may be no surprise that FlexGrid is the most popular datagrid. It’s one of the longest-running controls originating from the VB6 VSFlexGrid control for ActiveX. The most useful feature of FlexGrid is the simple Subtotal method, which groups the grid by any column and aggregates, or subtotals, that column to display the total in the group header row. You can read more about how the standard DataGridView stacks up against FlexGrid in our previous article.
2. Ribbon — A WinForms Ribbon UI provides a complete toolbar and menu system for a Windows desktop app that wants to replicate the same UI from Microsoft Office. One of the most versatile features is the ability to collapse the ribbon into a condensed toolbar. End users can toggle this runtime feature according to their preferences.
3. DockingTab — The DockingTab control provides WinForms floating panel behavior, where the whole control or individual panels (tabs) can be torn off and automatically docked to any other edge of the application or floated in a separate window. The DockingTab control provides a customizable workspace framework, similar to complex designer applications like Adobe Photoshop and Premiere.
4. Charts — Charts are consistently among the most popular third-party .NET UI controls because they are complex and difficult to write from scratch independently. ComponentOne FlexChart makes this list along with its family of specialized components: FlexPie, FlexRadar, Sunburst, Treemap, and FinancialChart.
5. Input -The C1TextBox and C1Button controls (as well as every ComponentOne Input control) support application-wide theming, the key feature not supported by the standard input controls. This means you can make all your text boxes and buttons blend seamlessly with whatever theme you have, whether it be white, modern, dark, material, or any other.
How to Add WinForms Controls to Your .NET Applications
Windows Forms provides one of the most productive ways to create desktop apps based on the visual designer provided in Visual Studio.
Create a Windows Forms Application
Let’s start by creating the .NET Windows Forms application that targets .NET 8.
- Open Visual Studio (note that you can build complete WinForms applications using the free Community edition of Visual Studio).
- Create a new “Windows Forms App” project.
- Select .NET 8 (Long Term Support) as the Target Framework.
- Open the default Form1.cs file.
How to Add Standard Controls through the Designer
UI controls can be added to a Windows Form by dragging and dropping them from the toolbox. Visual Studio generates the code-behind that instantiates, which can be specified as C# .NET or VB.NET, and positions the controls on the form.
Drag and drop some buttons and other controls to test it out.
While writing this code yourself would not be too difficult, it is very tedious. The WinForms visual designer saves a lot of time generating the application UI.
How to Add Third-Party Controls
Third-party WinForms controls are also added to the UI from the toolbox, but first, we must add them to the toolbox. There are two methods for adding third-party controls to the toolbox: DLL reference and NuGet package.
- DLL Reference — This is the original approach and can be used if you’ve downloaded a library assembly file (.dll) for your third-party control. Right-click the toolbox and select “Choose Items…”. From there, you can browse and locate your library.
- NuGet Package — This is the new way to work with all .NET components. Under the Visual Studio “Tools” menu, you can launch the “NuGet Package Manager” for the solution. Then, browse for your library from the public nuget.org source or any custom source. Once the package is installed, its controls will appear in your toolbox.
The major difference between these approaches is that adding the DLLs to the toolbox does not add them to the project. The control must be dropped to the design surface for the project reference to be added. With the NuGet package, you are first adding the project reference.
To test this out, browse for the C1.Win.FlexGrid package and install the latest version. You’ll observe this adds the C1FlexGrid control to your toolbox in its own group.
How to Data Bind WinForms Controls
The primary purpose of the UI controls is to collect input and display data to the user. Data binding is the process of “automatically” populating the UI controls with data from a data source, such as a database. When controls are data-bound, .NET handles most of the code for you. You simply have to specify what collection and field to bind.
Consider the following C# ViewModel class, which generates a collection of weather data. With the MVVM (Model-View-ViewModel) architectures, we specify a Model class for each business object (table in our data set). The UI controls are then bound to a collection of the business objects through this ViewModel.
public class ViewModel
{
private WeatherForecast[]? _forecasts;
public WeatherForecast[]? Forecasts
{
get
{
if(_forecasts == null)
{
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
_forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
return _forecasts;
}
}
}
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
At design time, WinForms controls rely on a BindingSource component, which acts as an intermediary that provides binding and currency management services. You bind the BindingSource to a collection of your objects, then set the DataSource property of your UI control to the BindingSource. However, in code, you can simply set it to any collection that inherits IList, IBindingList, or IEnumerable. Note that the code above returns an IEnumerable array and that the different collection types provide different data features.
dataGridView1.DataSource = Forecasts;
About WinForms Visual Styles and Themes
Visual appearance is another important factor to consider when using WinForms controls. Windows Forms is the oldest framework in .NET, but over the past two decades, the overall look and feel of the application has not improved. The intentional design of WinForms is to match the user’s Windows operating system. Thus, the WinForms UI controls inherit their style from the operating system colors.
Unfortunately, it’s not easy to customize the system colors for a single application. The solution is to inherit the control and create your own version that can override the low-level rendering. This allows you to customize the look of a WinForms UI control beyond its API. It’s not a typical task for a .NET developer, which is why third-party WinForms UI controls are very popular.
.NET WinForms control suites often include built-in themes and tools to customize the theme for you. For example, check out these advanced WinForms UI controls.
WinForms Controls vs WPF Controls
WPF (Windows Presentation Foundation) was released with .NET 3.0 as a potential replacement for WinForms. To this day, both platforms remain viable solutions for developing .NET desktop applications. The main difference is that WPF components are implemented using XAML, which can make customization easier but can arguably make the overall UI development a bit more complicated than WinForms.
Some key arguments in the debate include:
- XAML is easier to customize and data bind
- WinForms controls are more abundant and easier to build
- WPF can achieve the best performance
- Both are built on Win32 and support .NET Core
XAML is Easier to Customize and Data Bind
WPF uses XAML (similar to XML) to define and separate the user interface from business logic. WPF (and other XAML-based frameworks like WinUI) allow you to set properties and data binding directly in the markup. WPF is typically considered more MVVM-friendly because data binding is very straightforward, thanks to the DataContext concept. In the WPF XAML example below, we set the DataContext for the Window so that its children can easily bind the ViewModel.
<Window ...>
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<DataGrid x:Name="dataGrid" ItemsSource="{Binding Forecasts}"/>
</Grid>
</Window>
XAML-based components are inherently more customizable with styles and control templates. Styles encapsulate properties into reusable resources (i.e., you can design one style that is applied across an entire application). If you need to customize a WPF UI control further, you can customize its XAML template — which is generally considered a step easier than overriding WinForms renderers but still is not a simple task for the average developer.
Many third-party libraries offer a rich API for appearance customization that saves a lot of development time. ComponentOne WPF controls provide extensive brush and color properties that allow you to customize the look of controls without needing themes or custom templates. Plus, some built-in themes, such as Google’s Material and Microsoft Office-inspired themes, are provided.
WinForms Controls are More Abundant and Easier to Build
WinForms has been around longer and still has a higher adoption rate than WPF, which means there are more WinForms controls on the market. So, if your application has some specific niche requirement, you’ll have more luck finding a WinForms control for that.
Since WinForms UIs are defined using C#, it’s not as visual on its own. Microsoft had to develop the “design time” experience for WinForms with a drag-and-drop feature and many click-through wizards to configure parts of the application. As a result, WinForms design time is richer and more evolved than WPF, and it’s the reason many developers still prefer WinForms.
WPF Can Achieve the Best Performance
WPF is built upon DirectX, a lower-level rendering engine that allows optimal performance on Windows. WinForms, on the other hand, typically uses GDI+ (graphics device interface), which is a legacy graphics drawing library. Generally, DirectX is considered superior.
WPF is More Scalable
WPF is also more scalable than WinForms due to its XAML architecture. Every non-web .NET framework that Microsoft has developed since WPF has used the same markup language (XAML), including WinUI. WinUI is used to create modern, Universal Windows applications, otherwise known as Microsoft Store apps. It uses XAML UI components, which are similar to WPF.
Building Custom WinForms Controls
Due to the .NET framework’s extensibility, anyone can build their own WinForms UI controls. A custom UI control is just a few C# classes that contain some public properties, events, and methods that handle things like rendering and recycling.
Depending on how complex your custom control is, you may be able to take advantage of the .NET UserControl class. This provides a lot of the work for you, allowing you to focus directly on the logic. UserControls are often built using a combination of other existing UI controls, but they will enable you to embed your own custom logic into a reusable package.
For example, if your custom control can be created by combining a ComboBox and a Button, you can use the UserControl template in Visual Studio. If your custom control can’t be created by simply using standard controls, then you have to build a completely custom control from scratch. See how to create custom controls in .NET for more information.
When to Buy vs Build a WinForms Control
You and your boss may wonder when you should purchase third-party WinForms controls instead of building them yourself. Obviously, the cost for developers is high, so you should consider the time and maintenance put into developing the controls yourself.
It’s recommended to build your own custom UI controls if:
- You can afford the extra development time
- You have enough time
- You have a particular requirement that may not be supported in an “off-the-shelf” control
- The application is a one-off that will not need to be maintained
You may have heard the saying, “Fast, cheap, or good: pick two.” It means if you want it to be cheap and good, don’t expect to get it any time soon; if you want it to be fast and good, expect to spend a lot of money.
It’s best to purchase UI controls when:
- The application has a long lifespan
- Your deadlines are short
- Your developers are also the support team
- You can afford it
If you’re the developer, the designer, the QA, and everything in between, a licensed toolkit from a respected company will be invaluable. The amount of time you save using third-party controls during the initial development period is multiplied over time, meaning five to ten years down the road, you’ve saved five to ten times more effort than you would otherwise spend maintaining your own custom controls. Yes, it’s an added annual cost. Still, for that price, you get an extended support team, a community of users, and, in the case of ComponentOne WinForms controls, frequent updates that resolve inevitable issues like browser and .NET version compatibility.
Conclusion
Windows Forms is a powerful .NET platform for building fast software applications on Windows. The WinForms UI controls are an essential feature for the fast development cycle. When you combine standard WinForms controls with third-party controls, you can achieve all of your application requirements rapidly.
Despite being one of the oldest .NET technologies, WinForms continues to be widely adopted and is still used in new application development in 2024. Its replacements, such as WPF and WinUI, do offer some benefits, but they do not mark the end for WinForms, as it will continue to be a powerful and wise choice for desktop development.