This is a CLR Project (.NET Framework 4.5).
I have a ContextMenuStrip which is displayed when the right mouse button is pressed on a ToolStripMenuItem, since ToolStripMenuItem has no ContextMenuStrip property I had to set the right click event in the MouseUp event like this:
private: System::Void itemToolStripMenuItem_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (e->Button == System::Windows::Forms::MouseButtons::Right) {
this->contextMenuStrip1->Show(this->menuStrip1,
this->menuStrip1->PointToClient(System::Drawing::Point(this->Cursor->Position.X, this->Cursor->Position.Y)));
}
}
I want the DropDown to remain open after a right mouse button click, I know that there's an AutoClose property that I could set to false:
private: System::Void contextMenuStrip1_Opening(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
this->itemsToolStripMenuItem->DropDown->AutoClose = false;
}
The problem is when setting AutoClose to false it won't close the DropDown anymore. I couldn't find a Leave event to close the DropDown and set AutoClose back to true.
I also need to keep a DropDown item highlighted after a right mouse button click.
This is what I'm trying to achieve:

The
menu.DropDown.Closing += ...;event is used to prevent the menu from closing if an item was right clicked. TheIsSelectedproperty is overridden in a derivedToolStripMenuItem3class in order to appear to remain selected.The
ToolStripMenuItemXclass: