Skip to content

Commit

Permalink
Add winforms whats new
Browse files Browse the repository at this point in the history
  • Loading branch information
adegeo committed Nov 12, 2024
1 parent eddaeb0 commit 113d467
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 12 deletions.
7 changes: 4 additions & 3 deletions dotnet-desktop-guide/net/winforms/whats-new/net50.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: What's new in Windows Forms .NET 5
description: Learn about what's new in Windows Forms for .NET 5. Windows Forms. .NET provides new features and enhancements over .NET Framework.
ms.date: 11/05/2020
ms.topic: conceptual
ms.date: 11/11/2024
ms.topic: whats-new
#customer intent: As a developer, I want to know what's changed so that I can remain up-to-date.
---

# What's new for .NET 5 (Windows Forms .NET)
# What's new in Windows Forms for .NET 5

Windows Forms for .NET 5 adds the following features and enhancements over .NET Framework.

Expand Down
7 changes: 4 additions & 3 deletions dotnet-desktop-guide/net/winforms/whats-new/net60.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: What's new in Windows Forms .NET 6
description: Learn about what's new in Windows Forms for .NET 6. Windows Forms. .NET provides new features and enhancements over .NET Framework.
ms.date: 11/11/2021
ms.topic: conceptual
ms.date: 11/11/2024
ms.topic: whats-new
#customer intent: As a developer, I want to know what's changed so that I can remain up-to-date.
---

# What's new for .NET 6 (Windows Forms .NET)
# What's new in Windows Forms for .NET 6

This article describes some of the new Windows Forms features and enhancements in .NET 6.

Expand Down
7 changes: 4 additions & 3 deletions dotnet-desktop-guide/net/winforms/whats-new/net70.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: What's new in Windows Forms .NET 7
description: Learn about what's new in Windows Forms for .NET 7. Windows Forms. .NET provides new features and enhancements over .NET Framework.
ms.date: 02/08/2023
ms.topic: conceptual
ms.date: 11/11/2024
ms.topic: whats-new
#customer intent: As a developer, I want to know what's changed so that I can remain up-to-date.
---

# What's new for .NET 7 (Windows Forms .NET)
# What's new in Windows Forms for .NET 7

This article describes some of the new Windows Forms features and enhancements in .NET 7.

Expand Down
7 changes: 4 additions & 3 deletions dotnet-desktop-guide/net/winforms/whats-new/net80.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: What's new in Windows Forms .NET 8
description: Learn about what's new in Windows Forms for .NET 8. Windows Forms. .NET provides new features and enhancements over .NET 7.
ms.date: 11/29/2023
ms.topic: conceptual
ms.date: 11/11/2024
ms.topic: whats-new
#customer intent: As a developer, I want to know what's changed so that I can remain up-to-date.
---

# What's new for .NET 8 (Windows Forms .NET)
# What's new in Windows Forms for .NET 8

This article describes some of the new Windows Forms features and enhancements in .NET 8.

Expand Down
125 changes: 125 additions & 0 deletions dotnet-desktop-guide/net/winforms/whats-new/net90.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: What's new in WinForms for .NET 9
description: Learn about what's new in Windows Forms for .NET 9. New versions of Windows Forms are released yearly with .NET.
ms.topic: whats-new
ms.date: 11/11/2024
#customer intent: As a developer, I want to know what's changed so that I can remain up-to-date.
---

# What's new in Windows Forms for .NET 9

This article describes what's new in Windows Forms for .NET 9. Windows Forms had improvements to security,

## Async forms

> [!IMPORTANT]
> This feature set is experimental.
Modern apps require asynchronous communication models. As Windows Forms has grown on .NET, more components require marshaling to an `async` method to run on the UI-thread. For example, controls like [WebView2](/microsoft-edge/webview2/), native Windows 10 and Windows 11 APIs, or modern asynchronous libraries like [Semantic Kernel](/semantic-kernel/overview/). Another scenario would be where you're sharing MVVM ViewModels built around `async` with Windows Forms from other UI stacks such as WPF, WinUI, or .NET MAUI.

The following a list of new methods added to support asynchronous scenarios:

- [System.Windows.Forms.Form.ShowAsync](xref:System.Windows.Forms.Form.ShowAsync(System.Windows.Forms.IWin32Window)?displayProperty=nameWithType)
- <xref:System.Windows.Forms.Form.ShowDialogAsync*?displayProperty=nameWithType>
- <xref:System.Windows.Forms.TaskDialog.ShowDialogAsync*?displayProperty=nameWithType>
- <xref:System.Windows.Forms.Control.InvokeAsync*?displayProperty=nameWithType>

This API is guarded behind a compiler error because it's experimental. Suppress the error to enable access to the API. Add the following `PropertyGroup` to your project file:

:::code language="xml" source=".\snippets\net90\csharp\MyExampleProject.csproj" id="experimental_async":::

> [!TIP]
> You can use the `#pragma warning disable WFO5002` directive to suppress the error where it occurs instead of disabling it for the entire project.
## BinaryFormatter no longer supported

`BinaryFormatter` is considered unsafe because it's vulnerable to deserialization attacks, which can lead to denial of service (DoS), information disclosure, or remote code execution. It was implemented before deserialization vulnerabilities were well understood, and its design doesn't follow modern security best practices.

Starting with .NET 9, its implementation has been removed to prevent these security risks. When `BinaryFormatter` is used, the `PlatformNotSupportedException` exception is thrown.

Windows Forms used `BinaryFormatter` in many scenarios, such as when serializing data for clipboard and drag-and-drop operations, and most importantly, the Windows Forms Designer. Internally, Windows Forms continues to use a safer subset of `BinaryFormatter` to handle specific use cases with a known set of types.

Windows Forms for .NET 9 is shipping with analyzers that help you identify times you unknowingly participate in binary serialization.

For more information about `BinaryFormatter`, see [Windows Forms migration guide for BinaryFormatter](/dotnet/standard/serialization/binaryformatter-migration-guide/winforms-applications).

## Dark mode

> [!IMPORTANT]
> This feature set is experimental.
Preliminary support for dark mode has been added to Windows Forms, with the goal of finalizing support in .NET 10. The color mode for the app can be set to one of the following values:

- `SystemColorMode.Classic`&mdash;(default) Light mode, the same as previous versions of Windows Forms.
- `SystemColorMode.System`&mdash;Respect the light or dark mode set by Windows.
- `SystemColorMode.Dark`&mdash;Use dark mode.

To apply a color mode, call <xref:System.Windows.Forms.Application.SetColorMode(System.Windows.Forms.SystemColorMode)?displayProperty=nameWithType> in the program startup code:

:::code language="csharp" source=".\snippets\net90\csharp\Program.cs" highlight="14":::
:::code language="vb" source=".\snippets\net90\vb\Program.vb" highlight="8":::

This API is guarded behind a compiler error because it's experimental. Suppress the error to enable access to the API. Add the following `PropertyGroup` to your project file:

:::code language="xml" source=".\snippets\net90\csharp\MyExampleProject.csproj" id="experimental_darkmode":::

> [!TIP]
> You can use the `#pragma warning disable WFO5001` directive to suppress the error where it occurs instead of disabling it for the entire project.
## FolderBrowserDialog enhancements

`FolderBrowserDialog` now supports selecting multiple folders, which are stored in the <xref:System.Windows.Forms.FolderBrowserDialog.SelectedPaths> array. To enable multiple folders, set <xref:System.Windows.Forms.FolderBrowserDialog.Multiselect> to `true`.

## System.Drawing new features and enhancements

The **System.Drawing** library has had many improvements, including wrapping GDI+ effects, support for `ReadOnlySpan`, and better interop code generation.

### System.Drawing supports GDI+ effects

The **System.Drawing** library now supports GDI+ bitmap effects, such as blur and tint. Effects have been a part of GDI+, but weren't exposed through **System.Drawing** until now.

Effects are applied to a <xref:System.Drawing.Bitmap> by calling the <xref:System.Drawing.Bitmap.ApplyEffect(System.Drawing.Imaging.Effects.Effect,System.Drawing.Rectangle)?displayProperty=nameWithType> method. Provide the effect and an optional `Rectangle` for the area to apply the effect on. Use <xref:System.Drawing.Rectangle.Empty?displayProperty=nameWithType> to process the entire image.

The <xref:System.Drawing.Imaging.Effects> namespace contains the effects you can apply:

- <xref:System.Drawing.Imaging.BlackSaturationCurveEffect>
- <xref:System.Drawing.Imaging.BlurEffect>
- <xref:System.Drawing.Imaging.BrightnessContrastEffect>
- <xref:System.Drawing.Imaging.ColorBalanceEffect>
- <xref:System.Drawing.Imaging.ColorCurveEffect>
- <xref:System.Drawing.Imaging.ColorLookupTableEffect>
- <xref:System.Drawing.Imaging.ColorMatrixEffect>
- <xref:System.Drawing.Imaging.ContrastCurveEffect>
- <xref:System.Drawing.Imaging.CurveChannel>
- <xref:System.Drawing.Imaging.DensityCurveEffect>
- <xref:System.Drawing.Imaging.ExposureCurveEffect>
- <xref:System.Drawing.Imaging.GrayScaleEffect>
- <xref:System.Drawing.Imaging.HighlightCurveEffect>
- <xref:System.Drawing.Imaging.InvertEffect>
- <xref:System.Drawing.Imaging.LevelsEffect>
- <xref:System.Drawing.Imaging.MidtoneCurveEffect>
- <xref:System.Drawing.Imaging.ShadowCurveEffect>
- <xref:System.Drawing.Imaging.SharpenEffect>
- <xref:System.Drawing.Imaging.TintEffect>
- <xref:System.Drawing.Imaging.VividEffect>
- <xref:System.Drawing.Imaging.WhiteSaturationCurveEffect>

### System.Drawing supports Span

Many methods that accepted arrays have been enhanced to also accept `ReadOnlySpan`. For example, methods such as <xref:System.Drawing.Drawing2D.GraphicsPath.AddLines(System.ReadOnlySpan{System.Drawing.Point})?displayProperty=nameWithType>, <xref:System.Drawing.Graphics.DrawLines(System.Drawing.Pen,System.ReadOnlySpan{System.Drawing.Point})?displayProperty=nameWithType>, and <xref:System.Drawing.Graphics.DrawPolygon(System.Drawing.Pen,System.ReadOnlySpan{System.Drawing.Point})>, accept an array or `ReadOnlySpan`.

### Use CsWin32 for interop

All interop code has been replaced by [CsWin32], a C# P/Invoke source generator.

## ToolStrip

The following improvements have been added to the <xref:System.Windows.Forms.ToolStrip> and <xref:System.Windows.Forms.ToolStripItem> controls.

- A new property was added to `ToolStrip`, <xref:System.Windows.Forms.ToolStrip.AllowClickThrough>.

When set to `true`, the control can be interacted with while the form is unfocused.

Back when .NET Core 3.1 was released, all `Menu`-related controls, such as `MainMenu` and `MenuItem`, were removed. `ToolStrip` and `ToolStripMenuItem` should be used instead. However, `ToolStripItem`, the base class for `ToolStripMenuItem`, didn't have a replacement for the `MenuItem.Select` event. This event was raised when the mouse or keyboard is used to highlight the item.

.NET 9 has added <xref:System.Windows.Forms.ToolStripItem.SelectedChanged?displayProperty=nameWithType>, which can be used to detect when a menu item is highlighted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Drawing.Drawing2D;

namespace MyExampleProject;

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private async void Button1_Click(object sender, EventArgs e)
{
label1.Text = "Starting....";
await label1.InvokeAsync(ChangeLabel);
//Form1 secondForm = new();
//await secondForm.ShowDialogAsync();
label1.Text = "Done";

}

void ChangeLabel()
{
for (int i = 0; i < 5; i++)
{
label1.Text = $"Counting down {6 - i} seconds..";
Task.Delay(1000);
}
}
}
Loading

0 comments on commit 113d467

Please sign in to comment.