This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
This article describes some of the new Windows Forms features and enhancements in .NET 7.
There are a few breaking changes you should be aware of when migrating from .NET Framework to .NET 7. For more information, seeBreaking changes in Windows Forms.
High DPI rendering withPerMonitorV2 has been improved:
Correctly scale nested controls. For example, a button that's in a panel, which is placed on a tab page.
ScaleForm.MaximumSize andForm.MinimumSize properties based on the current monitor DPI settings for applications that runApplicationHighDpiMode set toPerMonitorV2.
In .NET 7, this feature is disabled by default and you must opt in to receive this change. Starting with .NET 8, this feature is enabled by default and you need to opt out of it to revert to the previous behavior.
To enable feature, set theconfigProperties setting inruntimeconfig.json:
{ "runtimeOptions": { "tfm": "net7.0", "frameworks": [ ... ], "configProperties": { "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi": true, } }}This release adds further improvements to accessibility, including but not limited to the following items:
Many announcement-related issues observed in screen readers have been addressed, ensuring the information about controls is correct. For example,ListView now correctly announces when a group is expanded or collapsed.
More controls now provide UI Automation support:
Memory leaks related to running a Windows Forms application under assistive tools, such as Narrator, have been fixed.
Assistive tools now accurately draw focus indicators and report correct bounding rectangles for nested forms and some elements of composite controls, such asDataGridView,ListView, andTabControl.
The Automation UIExpandCollapse Control Pattern has been properly implemented inListView,TreeView, andPropertyGrid controls, and only activates for expandable items.
Various color contrast ratio corrections in controls.
Visibility improvements forToolStripTextBox andToolStripButton in high-contrast themes.
While Windows Forms already had a powerful binding engine, a more modern form of data binding, similar to data binding provided by WPF, is being introduced.
The new data binding features allow you to fully embrace the MVVM pattern and the use of object-relational mappers from ViewModels in Windows Forms easier than before. This, in turn, makes it possible to reduce code in the code-behind files, and opens new testing possibilities. More importantly, it enables code sharing between Windows Forms and other .NET GUI frameworks such as WPF, UWP/WinUI, and .NET MAUI. And to clarify a commonly asked question, there aren't any plans to introduce XAML in Windows Forms.
These new data binding features are in preview for .NET 7, and more work on this feature will happen in .NET 8.
To enable the new binding, add theEnablePreviewFeatures setting to your project file. This is supported in both C# and Visual Basic.
<Project Sdk="Microsoft.NET.Sdk"> <!-- other settings --> <PropertyGroup> <EnablePreviewFeatures>true</EnablePreviewFeatures> </PropertyGroup></Project>The following code snippet demonstrates the new properties, events, and methods added to the various classes in Windows Forms. Even though the following code example is in C#, it also applies to Visual Basic.
public class Control { [BindableAttribute(true)] public virtual object DataContext { get; set; } [BrowsableAttribute(true)] public event EventHandler DataContextChanged; protected virtual void OnDataContextChanged(EventArgs e); protected virtual void OnParentDataContextChanged(EventArgs e);}[RequiresPreviewFeaturesAttribute]public abstract class BindableComponent : Component, IBindableComponent, IComponent, IDisposable { protected BindableComponent(); public BindingContext? BindingContext { get; set; } public ControlBindingsCollection DataBindings { get; } public event EventHandler BindingContextChanged; protected virtual void OnBindingContextChanged(EventArgs e);}public abstract class ButtonBase : Control { [BindableAttribute(true)] [RequiresPreviewFeaturesAttribute] public ICommand? Command { get; set; } [BindableAttribute(true)] public object? CommandParameter { [RequiresPreviewFeaturesAttribute] get; [RequiresPreviewFeaturesAttribute] set; } [RequiresPreviewFeaturesAttribute] public event EventHandler? CommandCanExecuteChanged; [RequiresPreviewFeaturesAttribute] public event EventHandler? CommandChanged; [RequiresPreviewFeaturesAttribute] public event EventHandler? CommandParameterChanged; [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandCanExecuteChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandParameterChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnRequestCommandExecute(EventArgs e);}public abstract class ToolStripItem : BindableComponent, IComponent, IDisposable, IDropTarget { [BindableAttribute(true)] [RequiresPreviewFeaturesAttribute] public ICommand Command { get; set; } [BindableAttribute(true)] public object CommandParameter { [RequiresPreviewFeaturesAttribute] get; [RequiresPreviewFeaturesAttribute] set; } [RequiresPreviewFeaturesAttribute] public event EventHandler CommandCanExecuteChanged; [RequiresPreviewFeaturesAttribute] public event EventHandler CommandChanged; [RequiresPreviewFeaturesAttribute] public event EventHandler CommandParameterChanged; [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandCanExecuteChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnCommandParameterChanged(EventArgs e); [RequiresPreviewFeaturesAttribute] protected virtual void OnRequestCommandExecute(EventArgs e);}Here are some other notable changes:
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?