WI01041726 - Legacy Control Migration: ToolBar#12
Merged
Conversation
Fully implement ToolBar, ToolBarButton, and related types, replacing stubs with upstream WinForms runtime code. Add a modern demo form (ToolBarForm) showcasing all button types, state management, and toolbar features. Integrate a comprehensive test suite for ToolBar and ToolBarButton, including advanced tooltip and DPI scenarios. Update launcher UI and migration docs, add string resources and translations, and introduce a compatibility shim for Win32 interop. This completes ToolBar migration and enables full runtime and designer support.
Revamped MainForm to a two-column layout, adding a dedicated ToolBar section with new button and label. Adjusted control sizes, positions, and tab indices for consistency, and increased form height. Updated ToolBar label text for clarity. Removed pragma warning disables from several files, relying on expanded .editorconfig suppressions for code analysis and style warnings.
…R resource strings
Adil-WTG
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Legacy Control Migration: ToolBar
Scope
This document tracks the legacy
ToolBarfamily and its supporting types:ToolBarToolBarButtonCurrent Status
The
ToolBarfamily has been ported. All types have been replaced with full working implementations ported from the upstream runtime. The old stub layer — every file that previously threwPlatformNotSupportedException— has been replaced.Files ported / changed
ToolBar.csToolBarButtonCollectionToolBarButton.csToolBarAppearance.csToolBarButtonStyle.csToolBarTextAlign.csToolBarButtonClickEventArgs.csToolBarButtonClickEventHandler.csNew files added
LegacyToolBarInteropCompat.csToolBarNativeMethods(TB* Win32 constants, HICF flags enum, TBBUTTON / TBBUTTONINFO / NMTOOLBAR / NMTBHOTITEM / TOOLTIPTEXT structs, and low-level bit helpers)Files deleted
ToolBar.ToolBarButtonCollection.csToolBar.csResource changes
All
ToolBar-family design-time string resources (23 entries, e.g.ToolBarAppearanceDescr,ToolBarButtonClickDescr,ToolBarButtonsDescr, etc.) have been added toSR.resxand all13 language XLF files. The XLF files carry
state="translated"with translations sourcedfrom the upstream
dotnet/winformsrepository. The runtime exception stringsToolBarBadToolBarButtonandToolBarButtonInvalidDropDownMenuTypeare also sourced fromSR.resx.Migration Approach
Step 1 — Copy the baseline from upstream
Take each file verbatim from the upstream
dotnet/winformssource before the control wasremoved from the main runtime. The starting point retains:
namespace System.Windows.Forms { … })#nullable disableNativeMethods,SafeNativeMethods,ClientUtils, etc.Step 2 — Create
LegacyToolBarInteropCompat.csThe upstream source references internal helpers and Win32 constant definitions that no
longer exist in the current codebase. A thin compatibility shim is created in-folder:
ToolBarNativeMethodsTB*/CCS_*/TBSTYLE_*/TBSTATE_*/TBIF_*/TBN_*Win32 constants;HICFflags enum;TBBUTTON,TBBUTTONINFO,NMTOOLBAR,NMTBHOTITEM,TOOLTIPTEXTstructs;Utilhelper withMAKELONG/MAKELPARAM/HIWORD/LOWORDThe implementation files use
SourceGenerated.EnumValidator.Validate()instead of theupstream
ClientUtils.IsEnumValid(), andPInvokeCore.SendMessage/PInvoke.*insteadof
NativeMethods.*. The two legacyArgumentExceptionmessages are sourced fromSR.ToolBarBadToolBarButtonandSR.ToolBarButtonInvalidDropDownMenuTyperather thanthrough a separate shim type.
Step 3 — Add
SRDescriptionattributes and string resourcesAll public properties and events on
ToolBarandToolBarButtonare decorated with[SRDescription(nameof(SR.ToolBar*Descr))]attributes, matching the upstream metadata.The 23 required description SR keys were added to
SR.resxand propagated to all 13 XLF files.ToolBar.cs— 14 attributes added:Appearance,AutoSize,BorderStyle,Buttons,ButtonSize,Divider,DropDownArrows,ImageList,ImageSize,ShowToolTips,TextAlign,Wrappable,ButtonClick(event),ButtonDropDown(event)ToolBarButton.cs— 10 attributes added:DropDownMenu,Enabled,ImageIndex,ImageKey,PartialPush,Pushed,Style,Text,ToolTipText,VisibleRemaining Work
AccessibleObjectpatterns