Skip to content

ToolStripComboBox causes MenuStrip to not display properly #6724

@ghost

Description

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.
001-001.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.
002.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

001.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:

002.mp4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions