dotnet/winforms

ToolStripComboBox causes MenuStrip to not display properly

Open

#6.724 geöffnet am 20. Feb. 2022

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (922 Forks)batch import
area-controls-StripControlshelp wanted

Repository-Metriken

Stars
 (4.100 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 14T 22h) (56 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide