Right click context menu contains blank lines

Chuck Wright 0 Reputation points
2025-11-04T16:02:50.25+00:00

I have a WinForms context menu using MenuItems. The menu occasionally displays with blank menu items. I had researched this in the past and found the following link, but this link no longer works. Can you point me to the correct link?

https://answers.microsoft.com/en-us/windows/forum/all/right-click-menu-context-menu-contains-blank-lines/b5191eae-c7f6-4813-afa7-7bf4645a5547?page=35

Windows development | WinUI
{count} votes

1 answer

Sort by: Most helpful
  1. Danny Nguyen (WICLOUD CORPORATION) 3,840 Reputation points Microsoft External Staff Moderator
    2025-11-05T04:19:39.8633333+00:00

    Hi,

    The original Microsoft Answers / Q&A link you mentioned is gone because that content was retired during Microsoft’s migration. It wasn’t fully archived, so we can’t recover the exact original discussion.

    For your particular problem (showing blank lines in ContextMenu), the cause could be:

    • Menu rebuild inside the Popup event: clearing and adding items while Windows is laying out the native menu leaves empty slots.
    • Items created (or temporarily “hidden”) with empty or null Text, never restored.
    • “Hiding” instead of removing: leaving a MenuItem in the collection but trying to blank it out rather than calling Remove / Clear.
    • Owner‑draw handlers (MeasureItem, DrawItem) throwing or returning zero size—background paints, text doesn’t.
    • Cross‑thread updates to MenuItem.Text (no Invoke), so the paint sees an unset value.
    • Reusing the same MenuItem instance across different parents or re‑parenting right before display.

    Below are relevant official and community documents regarding practices on ContextMenu:

    Similar issue

    Modern (Recommended) API

    Compatibility / Migration

    If this doesn’t help, please share snippets of these code so I can pin point the problem:

    • Your current Popup (or Opening) event handler.
    • The method (if any) that builds or rebuilds the menu.
    • Any owner‑draw handlers.
    • Any background/threaded code that touches MenuItem.Text, MenuItems.Add, or removal.

    Happy to help further if there's any new information.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.