Windows Forms Gets Font Changes, Designers and More in .NET 6.0

Today we are looking at some of the most exciting new features and language changes coming to .Net 6.0 and, specifically, Windows Forms. These new features include changes to fonts, runtime designers, and TaskDialogue controls.

Windows Forms New Features: .Net 6.0

Here is a list of some of the new features coming to Windows Forms and .Net 6. We include some code examples to better explain their use and how they will affect .Net developers.

Application-wide Default Font

As its name implies, the Application-wide Default Font feature allows you to set a font application-wide one time without having to worry about setting fonts on each form and control manually. This saves developers a lot of time and reduces errors. Here’s how you can implement Application-wide default fonts in Window Forms in .Net 6:

class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
        Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8f));
        Application.Run(new Form1());
    }
}

The Application.SetDefaultFont method accepts a font family and a size as arguments. As you can see, I have included this code in the Main method of the Program.cs. If you were to attempt to set the default application wide font at a later stage of your program, it will not work and will produce an exception.

New Runtime Designers in Windows Forms

More runtime designers have been added in the latest Windows Forms update. Where we were accustomed to one big designer handling all the controls and the form designing duties before, the form’s designer has now been split up into multiple designers. Here is list of separate designers:

  • System.ComponentModel.Design.ComponentDesigner System.Windows.Forms.Design.ButtonBaseDesigner
  • System.Windows.Forms.Design.ComboBoxDesigner System.Windows.Forms.Design.ControlDesigner
  • System.Windows.Forms.Design.DocumentDesigner System.Windows.Forms.Design.FormDocumentDesigner
  • System.Windows.Forms.Design.GroupBoxDesigner System.Windows.Forms.Design.LabelDesigner
  • System.Windows.Forms.Design.ListBoxDesigner System.Windows.Forms.Design.ListViewDesigner
  • System.Windows.Forms.Design.MaskedTextBoxDesigner System.Windows.Forms.Design.PanelDesigner
  • System.Windows.Forms.Design.ParentControlDesigner System.Windows.Forms.Design.PictureBoxDesigner
  • System.Windows.Forms.Design.RadioButtonDesigner System.Windows.Forms.Design.RichTextBoxDesigner
  • System.Windows.Forms.Design.ScrollableControlDesigner System.Windows.Forms.Design.TextBoxBaseDesigner
  • System.Windows.Forms.Design.TextBoxDesigner System.Windows.Forms.Design.ToolStripDesigner
  • System.Windows.Forms.Design.ToolStripDropDownDesigner System.Windows.Forms.Design.ToolStripItemDesigner
  • System.Windows.Forms.Design.ToolStripMenuItemDesigner System.Windows.Forms.Design.TreeViewDesigner
  • System.Windows.Forms.Design.UpDownBaseDesigner System.Windows.Forms.Design.UserControlDocumentDesigner

This separation helps with creating controls individually. For instance, if you were to create a button, the normal System.Forms designer would not be used. Instead, a subset(System.Windows.Forms.Design.ButtonBaseDesigner)would be used.

New TaskDialog Control

The new TaskDialogue control is similar to a MessageBox except it shows more information. Here is an example of what it looks like in Windows Forms:

Windows Forms TaskDialogue Feature

Figure 1 – TaskDialog control *Image Credit: GitHub 

ListView Enhancements

In the new update, the ListView now includes the following new Properties:

CollapsedState 0 – Default: Non-collapsible group, expanded

1 – Expanded: Collapsible group, expanded

2 – Collapsed: Collapsible group, collapsed

Footer

Text that is displayed in the group footer

Subtitle

Text that is displayed in the group subtitle

TaskLink

The name of the task link displayed in the group header

TitleImageIndex

Gets or sets the index of the image displayed for the group

Table 1 – ListView properties

A preview of the new ListView can be seen below:

Windows Forms ListView

Figure 2 – ListView *Image credit: Microsoft

Other Updates to Windows Forms and New .Net 6 Features

For now, this seems to be some of the most important changes to Windows Forms and .NET 5. We will continue to update this article as more features are announced and added, so be sure to check back often for the latest on Windows Forms and .Net updates.

You can also check the DevBlog at Windows for more updates about features coming to Windows Forms and .Net 6.

Hannes DuPreez
Hannes DuPreez
Ockert J. du Preez is a passionate coder and always willing to learn. He has written hundreds of developer articles over the years detailing his programming quests and adventures. He has written the following books: Visual Studio 2019 In-Depth (BpB Publications) JavaScript for Gurus (BpB Publications) He was the Technical Editor for Professional C++, 5th Edition (Wiley) He was a Microsoft Most Valuable Professional for .NET (2008–2017).

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read