From 1333f218ed2a40df44fd88e892f76834f68f3444 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 22 Apr 2021 16:17:19 -0400 Subject: [PATCH] Add MetadataUpdateHandler to WinForms to repaint all open forms --- .../Internal/WinFormsMetadataUpdateHandler.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsMetadataUpdateHandler.cs diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsMetadataUpdateHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsMetadataUpdateHandler.cs new file mode 100644 index 00000000000..fbe85b20945 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsMetadataUpdateHandler.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Reflection.Metadata; +using System.Windows.Forms; + +[assembly: MetadataUpdateHandler(typeof(WinFormsMetadataUpdateHandler))] + +namespace System.Windows.Forms +{ + /// Handle notifications of metadata updates being applied. + internal static class WinFormsMetadataUpdateHandler + { + /// Invoked after a metadata update is applied. + /// The list of types known to be updated, or null if it couldn't be determined. + internal static void AfterUpdate(Type[]? types) + { + // Repaint all open forms. + foreach (Form openForm in Application.OpenForms) + { + openForm.BeginInvoke((MethodInvoker)(() => openForm.Refresh())); + } + } + } +}