winforms icon indicating copy to clipboard operation
winforms copied to clipboard

ContextMenuStrip has erroneous behavior if ToolStripMenuItem item Available=false

Open BigBauf opened this issue 3 years ago • 2 comments

.NET version

Net 7.0 Preview1

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

no

Issue description

If you add a ToolStripMenuItem to a ContextMenuStrip with the flag 'available' = false already set, it brakes the scrolling behavior.

ErrorDemo

If you set the flag after all items are added it works fine.

Steps to reproduce

Reproduced process: ContextMenuStrip.Items - order //breaks: [0] available = true [1] available = false [2] available = true //works: [0] available = false [1] available = false [2] available = true

Test C# Code

using System;
using System.Windows.Forms;

namespace ContextMenuStripItemAvailableTest
{
	static class Program
	{
		[STAThread]
		static void Main()
		{
			Application.SetHighDpiMode(HighDpiMode.SystemAware);
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			var contextMenuStrip = new ContextMenuStrip
			{
				MaximumSize = new Size(400, 200),//just for easier testing
			};

			var itemManual = new ToolStripMenuItem("item_manual");
			contextMenuStrip.Items.Add(itemManual);

			var itemHidden = new ToolStripMenuItem("item_hidden");

			//breaks the rendering
			itemHidden.Available = false;

			contextMenuStrip.Items.Add(itemHidden);

			for (int i = 0; i < 20; i++)
			{
				var tsi = new ToolStripMenuItem("item_" + i);
				contextMenuStrip.Items.Add(tsi);
			};

			///works fine 
			//contextMenuStrip.Items[1].Available = false; //1=itemHidden

			var frm = new Form()
			{
				StartPosition = FormStartPosition.CenterScreen,
				ContextMenuStrip = contextMenuStrip,
				Width = 600,
				Height = 400,
			};
			Application.Run(frm);
		}
	}
}


PS: There are other rendering bugs that happens if available is used. I can not describe the exact way to reproduce the error and for that reason i can only confirm this behavior for Net Framework 4.8. Example 1: Scrolling is working but if the bottom of the item list is reached the contextmenu expands to the bottom of the screen and the addtionals space is filled with empty items. Example 2: Scrolling works and when you reach the bottom and scrool up again you can not reach the top of the list ever again. From 100 Items you can only go up to 40 and then it jumps down to 100 again. It is just a loop from no on.

BigBauf avatar Aug 22 '22 10:08 BigBauf

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

Happy Coding!

ghost avatar Aug 23 '22 20:08 ghost

@BigBauf , thank you for filing this. Since this is not a regression, it will not be on priority list for the team. If you like to come up with a solution, we will assist you with validation and release process.

dreddy-work avatar Aug 23 '22 21:08 dreddy-work