question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ToolStripComboBox causes MenuStrip to not display properly

See original GitHub issue

C# Code: .Net 6.0 with Visual studio 2022

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ToolStripItemTest
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();
            Application.Run(CreateForm());
        }

        private static Form CreateForm()
        {
            var form = new Form()
            {
                Width = 1024,
                Height = 768,

                StartPosition = FormStartPosition.CenterScreen,
            };

            var mainMenu = new MenuStrip()
            {
                Dock = DockStyle.Top,
            };

            var menu1 = new ToolStripMenuItem("Menu 1");

            var subMenu1 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu2 = new ToolStripMenuItem("Sub Menu Item 2");
            var subMenu3 = new ToolStripMenuItem("Sub Menu Item 3");

            //You can replace it to ToolStripTextBox Control.
            var subMenu4 = new ToolStripComboBox("Sub Menu Item 4") { DropDownStyle = ComboBoxStyle.DropDownList };

            var subMenu5 = new ToolStripMenuItem("Sub Menu Item 5");
            var subMenu6 = new ToolStripMenuItem("Sub Menu Item 6");
            var subMenu7 = new ToolStripMenuItem("Sub Menu Item 7");
            var subMenu8 = new ToolStripMenuItem("Sub Menu Item 8");


            menu1.DropDownItems.Add(subMenu1);
            menu1.DropDownItems.Add(subMenu2);
            menu1.DropDownItems.Add(subMenu3);
            menu1.DropDownItems.Add(subMenu4);
            menu1.DropDownItems.Add(subMenu5);
            menu1.DropDownItems.Add(subMenu6);
            menu1.DropDownItems.Add(subMenu7);
            menu1.DropDownItems.Add(subMenu8);

            var subMenu3_Sub1 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu3_Sub2 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu3_Sub3 = new ToolStripMenuItem("Sub Menu Item 1");

            subMenu3.DropDownItems.Add(subMenu3_Sub1);
            subMenu3.DropDownItems.Add(subMenu3_Sub2);
            subMenu3.DropDownItems.Add(subMenu3_Sub3);

            var subMenu6_Sub1 = new ToolStripControlHost(new Control() { Width = 200, Height = 60, BackColor = Color.LightGreen });
            subMenu6.DropDownItems.Add(subMenu6_Sub1);

            mainMenu.Items.Add(menu1);

            form.Controls.Add(mainMenu);

            return form;
        }
    }
}

Test Result:

Video 1:

  1. Open the menu.
  2. Click the combobox menu item.
  3. move your mouse to other menu items.
  4. Then you will find that the Menu Hover effect disappears completely, and when the mouse moves over other items, the menu items will no longer display the blue background and it cannot automatically expand its submenus unless you click the left mouse button. After this, it still shows various incorrect Hover effects.

https://user-images.githubusercontent.com/88176616/154834883-ed39e8b1-3687-40f7-9145-daa2378b85cb.mp4

Video 2:

  1. Open the menu.
  2. Move the mouse over the menu item with submenu items.
  3. Move the mouse to the ComboBox menu item. You will find that the previous menu does not close automatically and still retains the blue background.

https://user-images.githubusercontent.com/88176616/154834943-76a70376-a45f-4d5d-b61b-f9b446134a1a.mp4

Supplement 1 (2022-03-08).

The ToolStripTextBox Control also does not work. It also flickers strongly when you move the mouse. https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.toolstriptextbox

https://user-images.githubusercontent.com/88176616/157164302-bbee8aa6-af83-452a-95b1-fb31ee755dd7.mp4

Supplement 2 (2022-03-08).

The ToolStripControlHost Control also does not work. https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.toolstripcontrolhost

Does not work: ToolStripControlHost with NumericUpDown Control. Does not work: ToolStripControlHost with TrackBar Control.

I haven’t tested other controls for compatibility at the moment.

Test Code:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ToolStripItemTest
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();
            Application.Run(CreateForm());
        }

        private static Form CreateForm()
        {
            var form = new Form()
            {
                Width = 1024,
                Height = 768,

                StartPosition = FormStartPosition.CenterScreen,
            };

            var mainMenu = new MenuStrip()
            {
                Dock = DockStyle.Top,
            };

            var menu1 = new ToolStripMenuItem("Menu 1");

            var subMenu1 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu2 = new ToolStripMenuItem("Sub Menu Item 2");
            var subMenu3 = new ToolStripMenuItem("Sub Menu Item 3");

            //You can replace it to ToolStripTextBox Control.
            var subMenu4 = new ToolStripComboBox("Sub Menu Item 4") { DropDownStyle = ComboBoxStyle.DropDownList };

            var subMenu5 = new ToolStripMenuItem("Sub Menu Item 5");
            var subMenu6 = new ToolStripMenuItem("Sub Menu Item 6");
            var subMenu7 = new ToolStripMenuItem("Sub Menu Item 7");
            var subMenu8 = new ToolStripMenuItem("Sub Menu Item 8");


            menu1.DropDownItems.Add(subMenu1);
            menu1.DropDownItems.Add(subMenu2);
            menu1.DropDownItems.Add(subMenu3);
            menu1.DropDownItems.Add(subMenu4);
            menu1.DropDownItems.Add(subMenu5);
            menu1.DropDownItems.Add(subMenu6);
            menu1.DropDownItems.Add(subMenu7);
            menu1.DropDownItems.Add(subMenu8);

            var subMenu3_Sub1 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu3_Sub2 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu3_Sub3 = new ToolStripMenuItem("Sub Menu Item 1");

            subMenu3.DropDownItems.Add(subMenu3_Sub1);
            subMenu3.DropDownItems.Add(subMenu3_Sub2);
            subMenu3.DropDownItems.Add(subMenu3_Sub3);

            var subMenu6_Sub1 = new ToolStripControlHost(new NumericUpDown() { MinimumSize = new Size(200, 0) });

            var subMenu6_Sub1_Sub1 = new ToolStripMenuItem("Sub Menu Item 1");
            var subMenu6_Sub1_Sub2 = new ToolStripMenuItem("Sub Menu Item 2");
            var subMenu6_Sub1_Sub3 = new ToolStripMenuItem("Sub Menu Item 3");

            subMenu6.DropDownItems.Add(subMenu6_Sub1);

            subMenu6.DropDownItems.Add(subMenu6_Sub1_Sub1);
            subMenu6.DropDownItems.Add(subMenu6_Sub1_Sub2);
            subMenu6.DropDownItems.Add(subMenu6_Sub1_Sub3);

            mainMenu.Items.Add(menu1);

            form.Controls.Add(mainMenu);

            return form;
        }
    }
}

Test Result:

https://user-images.githubusercontent.com/88176616/157165789-edc5deb9-ca39-4471-96ca-fc28cbe7b454.mp4

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
roland5572commented, Feb 20, 2022

The same problem in .net framework 4.8.

0reactions
msftbot[bot]commented, May 5, 2022

This issue is now marked as “up for grabs”, and we’re looking for a community volunteer to work on this issue. If we receive no interest in 120 days, we will close the issue. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# toolstrip doesn't dock under menustrip
When I manually add the toolstrip to the form using the forms designer, the toolstrip is correctly positioned under the menustrip.
Read more >
ToolStripComboBox Class (System.Windows.Forms)
Represents a ToolStripComboBox that is properly rendered in a ToolStrip. ... Gets a value indicating whether to show or hide shortcut keys.
Read more >
[RESOLVED] Disabled MenuStrip item bug
A disabled item, showing it's sub items. 1. To duplicate the error, you simply add a menustrip component, and add at least two...
Read more >
ToolstripComboBox
It's really that toolstrip combo that bugging me. I tried it last night and i couldn't get it to work. It doesn't make...
Read more >
Thread: [Ready] Visual Studio 2010 Menu/ToolStrip
Known issues: - Some things do not render properly when the ToolStrip is in vertical layout mode. - I cannot control rendering of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found