ToolStripComboBox causes MenuStrip to not display properly
See original GitHub issueC# 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:
- Open the menu.
- Click the combobox menu item.
- move your mouse to other menu items.
- 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.
Video 2:
- Open the menu.
- Move the mouse over the menu item with submenu items.
- 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.
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
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:
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The same problem in .net framework 4.8.
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!