Skip to content

Rewrite deprecated WinForms MainMenu/MenuItem/ToolBar classes for .NET 8 compatibility#1926

Closed
Copilot wants to merge 1 commit into
mainfrom
copilot/update-menu-toolbar-classes
Closed

Rewrite deprecated WinForms MainMenu/MenuItem/ToolBar classes for .NET 8 compatibility#1926
Copilot wants to merge 1 commit into
mainfrom
copilot/update-menu-toolbar-classes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

Summary

Replaces the removed/deprecated System.Windows.Forms classes (MainMenu, MenuItem, ContextMenu, ToolBar, ToolBarButton) with their modern ToolStrip-based equivalents so the GUI SDK compiles and runs on .NET 8+.

Changes

WinForm/MenuToolbar.prg (core rewrite)

  • VOMenu now inherits MenuStrip (was MainMenu)
  • VOMenuItem now inherits ToolStripMenuItem (was MenuItem)
    • Stores click/select/popup handler delegates as fields for safe cloning
    • CloneMenu() reconstructs a deep copy with all handlers preserved
    • RemoveFromParent() removes from DropDownItems or top-level Items
    • SetShortCut(LONG) sets ShortcutKeys
  • VOToolBar now inherits ToolStrip (was ToolBar)
    • ButtonSize property maps to ImageScalingSize
    • GetButton() searches Items collection
  • VOToolBarButton now inherits ToolStripButton (was ToolBarButton)
    • Pushed maps to Checked; Rectangle maps to Bounds
  • VOSeparator wraps ToolStripSeparator
  • AsContextMenuStrip() replaces AsContextMenu() — builds a ContextMenuStrip from cloned items

Menu/Accelerator.prg

  • AcceleratorKey.Shortcut now returns System.Windows.Forms.Keys (the Shortcut enum was removed in .NET 5+)

Menu/Menu.prg

  • AppendItem / InsertItem: use Items instead of MenuItems; separators create ToolStripSeparator directly
  • DeleteItem: uses RemoveFromParent() helper
  • GetSubMenu: uses CloneMenu() on the new API
  • SetShortCuts / __ClearShortCuts: iterate ToolStripItemCollection using ShortcutKeys / Keys.None
  • __CreateMenuItem: wires MouseEnter (was Select) and DropDownOpened (was Popup)
  • ShowShortcutKeys replaces ShowShortcut
  • Helper functions GetMenuItemCount / GetSubMenu updated

Menu/ToolBar.prg

  • OnControlCreated: uses ShowItemToolTips, GripStyle.Hidden, and ItemClicked event
  • ItemClicked replaces ButtonClick as the click handler
  • AppendItem / InsertItem: separators use VOSeparator, buttons use Items.Add/Insert
  • DeleteItem: uses Items.IndexOf + Items.RemoveAt
  • ButtonStyle setter: iterates Items.OfType<VOToolBarButton>()
  • Flat assign: uses ToolStripRenderMode instead of ToolBarAppearance
  • ButtonCount: uses Items.Count
  • __CreateButton and __GetButton return typed VOToolBarButton

ResourceReader/ResourceMenu.prg

  • AddItemsTo: uses a List<OBJECT> stack; dispatches to Items.Add or DropDownItems.Add based on current context type

Windows/Window.prg

  • Menu setter: adds VOMenu to Form.Controls and sets Form.MainMenuStrip
  • ContextMenu property: sets Form.ContextMenuStrip
  • ContextMenuShow: shows Form.ContextMenuStrip

Windows/ChildAppWindow.prg

  • Menu setter: replaces deprecated MdiList/MergeType with Form.MdiWindowListItem

Windows/ShellWindow.prg

  • Menu setter: replaces MenuItem.MdiList with Form.MdiWindowListItem

Windows/Application Window.prg

  • Activate: replaces oShell:Form.Menu assignment with ToolStripManager.Merge() for MDI menu merging

Controls/Control.prg

  • ContextMenu property: sets Control.ContextMenuStrip instead of Control.ContextMenu

…NET 8 compatibility

Agent-Logs-Url: https://github.com/X-Sharp/XSharpPublic/sessions/7c8c5d6c-0b83-4522-ba7c-9f3497d3af4d

Co-authored-by: RobertvanderHulst <14240939+RobertvanderHulst@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants