0

I'm scratching my head on this one. A user turned in a bug report that when they resize the form by double clicking the header the tool strip menu item that moves under the mouse is clicked.

I've isolated it to the tool strip menu item being under the mouse by creating a new .NET project with a WinForms .NET form > Adding a MenuStrip > Adding a ToolStripMenuItem > setting the click on the ToolStripMenuItem to a popup box saying that it was clicked.

When I move the form so my mouse will be over the ToolStripMenuItem when the form resizes, then double click the header, the form goes full screen and I get the popup that I clicked the ToolStripMenuItem.

If I replace the MenuStrip with a button the issue does not reproduce.

Any idea how to fix this short of adding a DateTime for the last refresh and updating all the ToolStripMenuItem click events to not process clicks within 100ms of the form resizing?

public partial class Form1 : Form
{
    private DateTime _doNotClickMenuItemsUntil = DateTime.MinValue;

    public Form1()
    {
        InitializeComponent();
    }

    private void toolStripMenuItem1_Click(object sender, EventArgs e)
    {
        if (DateTime.Now > _doNotClickMenuItemsUntil)
            MessageBox.Show("toolStripMenuItem1_Click!");
    }

    private void Form1_Resize(object sender, EventArgs e)
    {
        _doNotClickMenuItemsUntil = DateTime.Now.AddMinutes(100);
    }
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Nothing here helps to reproduce the problem. Anyway. what you are saying does not happen. Double check your code and use your debugger to get the main caller. Btw, `DateTime.Now.AddMinutes(100)` adds 1 hour and 40 minutes not 100 milliseconds. – dr.null Oct 06 '22 at 18:57
  • I can't reproduce this either. Try re-creating the problem in a new project and post that code. – LarsTech Oct 06 '22 at 19:08

0 Answers0