dotnet / dotnet/winforms

Application Crash and Menu Not Added in ToolStrip when Using ToolStripControlHost with a Custom UserControl

Open
#13,132 1 comment 0 reactions 0 assignees View on GitHub
area-VSDesigner
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### Environment

Edition - Windows 11 Enterprise
Version - 23H2
OS build - 22631.3737
Visual Studio version - 17.12.2

### .NET version

NET90

### Did this work in a previous version of Visual Studio and/or previous .NET release?

No

### Issue description

Requirement:

I need to create a custom dropdown menu as a UserControl. The goal is to use this custom menu in various ToolStrip controls across different TabPages within a TabControl.

Issue Faced:

While implementing this feature, I encountered two critical issues:

1.Menu Not Added to ToolStrip:
Despite correctly adding the custom menu UserControl to the ToolStrip via ToolStripControlHost, the menu does not appear as expected. The ToolStripControlHost is not rendering the menu inside the ToolStrip control.

2.Application Crash:
In addition to the above, when trying to add the custom UserControl to the ToolStrip, the application crashes. This occurs specifically when using ToolStripControlHost to host the UserControl.

### Steps to reproduce

1.Create a new Windows Forms project.
2.Add a TabControl with multiple TabPages in the form
3.Create a UserControl (Menu) that contains a ToolStrip with a ToolStripDropDownButton and a few ToolStripMenuItems.
4.In the Form1 designer, use ToolStripControlHost to host the Menu UserControl and add it to the ToolStrip in TabPage1.
5.Run the application.
6.The menu should appear in the ToolStrip, but an application crash occurs when trying to close and reopen the design files.

[TabControl_VB.zip](https://github.com/user-attachments/files/19228047/TabControl_VB.zip)

[Recording 2025-03-13 165846.zip](https://github.com/user-attachments/files/19228100/Recording.2025-03-13.165846.zip)

### Diagnostics

```text

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.