I'm working on a VB Winforms project (although I'm just as fine with a C# solution) and have the following set up:
msCreateReports
Create Reports
and its DropDown
set to msCreateReports
cmdCreateReports
Now, for my command button, I have the following code for its click
event:
Private Sub cmdCreateReports_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreateReports.Click
msCreateReports.Show(Cursor.Position.X, Cursor.Position.Y)
End Sub
EDIT (Update / Explanation):
Basically, what I'm looking for functionality-wise is to have this contextmenustrip be able to show up in one of 2 different places, depending on where the user clicks...
If they click on the menu option, the context menu appears as a drop-down on the Create Reports
menu item OR if the user clicks the command button, the menu will apeear as a context menu on the side of the mouse pointer. I want the same menu to be able to appear on either one of these two locations depending on where the user clicks to make this menu appear.
Now, my problem is that only the first time the command button is clicked, the ContextMenuStrip appears up top by the menu, rather than on top of the command button, as I would like it to.
After the first click, the menu appears in the correct location... What did I do wrong / how can I fix this??
Thanks!!
I have the same problem (I'm using Visual Studio 2010 SP1, and C#). I don't think we did anything wrong, it looks like a Winforms bug to me.
I fixed it like this:
1) I have unset (using the visual designer) the DropDown
property of the main strip item.
2) I have defined the Opening event on the contextMenuStrip, and the DropDownOpening event on the main strip item like this:
private void toolStripMyMenuItem_DropDownOpening(object sender, EventArgs e)
{
toolStripMyMenuItemMyLists.DropDown = contextMenuStrip;
}
private void contextMenuStrip_Opening(object sender, CancelEventArgs e)
{
toolStripMyMenuItemMyLists.DropDown = contextMenuStrip;
}
And I don't have this problem anymore. Hope it will help you too :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With