all groups > vb.net > april 2005 >
vb.net :
How to catch a right-click
How can I catch a right-click on a DropDownMenuItem?
I too would like to know. It's too bad that M'soft just passes the EventArgs type object to the click event...it would seem that they could have passed the MouseEventArgs type instead...the EventArgs is useless [quoted text, click to view] "Terry Olsen" wrote: > How can I catch a right-click on a DropDownMenuItem? > >
Hi Terry, To my knowledge there isn't a way to determine whether a click on a menu item was a right or a left click (well, probably no simple way). Why do you need to catch right clicks? Perhaps there's an alternate way to do what you're doing without using MenuItems. Regards, -Adam. [quoted text, click to view] Terry Olsen wrote: > How can I catch a right-click on a DropDownMenuItem? >
I want to be able to right-click a DropDownMenuItem and have a context menu popup that allows me to delete that MenuItem. Like you can do in IE. [quoted text, click to view] "Adam Goossens" <adam.goossens@gmail.com> wrote in message news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... > Hi Terry, > > To my knowledge there isn't a way to determine whether a click on a menu > item was a right or a left click (well, probably no simple way). > > Why do you need to catch right clicks? Perhaps there's an alternate way to > do what you're doing without using MenuItems. > > Regards, > -Adam. > > Terry Olsen wrote: >> How can I catch a right-click on a DropDownMenuItem?
[quoted text, click to view] "Adam Goossens" <adam.goossens@gmail.com> wrote in message news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... > Hi Terry, > > To my knowledge there isn't a way to determine whether a click on a menu > item was a right or a left click (well, probably no simple way).
There must be some way as Word has a DocumentBeforeRightClickEvent. Dunno how it works internally.
I've found a way using the MouseDown event for the MenuItem. However, I have dynamically created menu items where I create MenuItem object, add it to the MenuBar, and then let go of the object. So without the object, I can't catch the right-click event. I guess I've got to come up with a way to hang on to each dynamically created MenuItem object so I can catch the right-click and remove the item from the MenuBar. [quoted text, click to view] "Howard Kaikow" <kaikow@standards.com> wrote in message news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... > "Adam Goossens" <adam.goossens@gmail.com> wrote in message > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... >> Hi Terry, >> >> To my knowledge there isn't a way to determine whether a click on a menu >> item was a right or a left click (well, probably no simple way). > > There must be some way as Word has a DocumentBeforeRightClickEvent. > Dunno how it works internally. > >
I couldn't find where the MenuItem had a MouseDown event...are you sure. Also, if you are "letting go of the object" by setting it to nothing or disposing it, you can no longer show it in the Menu bar or Context Menu PopUp, or whatever. What do you mean by "letting go"? If you can display it, it's still there and you should be able to get to it's events. [quoted text, click to view] "Terry Olsen" wrote: > I've found a way using the MouseDown event for the MenuItem. However, I > have dynamically created menu items where I create MenuItem object, add it > to the MenuBar, and then let go of the object. So without the object, I > can't catch the right-click event. I guess I've got to come up with a way > to hang on to each dynamically created MenuItem object so I can catch the > right-click and remove the item from the MenuBar. > > "Howard Kaikow" <kaikow@standards.com> wrote in message > news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... > > "Adam Goossens" <adam.goossens@gmail.com> wrote in message > > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... > >> Hi Terry, > >> > >> To my knowledge there isn't a way to determine whether a click on a menu > >> item was a right or a left click (well, probably no simple way). > > > > There must be some way as Word has a DocumentBeforeRightClickEvent. > > Dunno how it works internally. > > > > > >
The following routine is what I use to add the MenuItem to a menu. As you can see, the scope of the object is local to the Subroutine, so once I leave the routine, I no longer have access to it, but it has been added to the menubar so it continues to display and I can click on it and respond to it using the 2nd routine listed below. The only way I can figure out how to catch a right-click is to make a global array of MenuItems and add event handlers for each one. Then I'll be able to respond to MouseDown events. Sub AddFavoriteToMenu(ByVal FavoriteName As String) Dim MenuItem As New ToolStripMenuItem MenuItem.Text = FavoriteName FavoritesToolStripMenuItem.DropDownItems.Add(MenuItem) End Sub Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles FavoritesToolStripMenuItem.DropDownItemClicked Dim tmp As String = e.ClickedItem.ToString If tmp = "A&dd" Then Exit Sub FavoriteMenuItemClicked(e.ClickedItem.ToString) End Sub [quoted text, click to view] "Dennis" <Dennis@discussions.microsoft.com> wrote in message news:9F6B790E-8124-443C-99EE-362ED73CA83F@microsoft.com... >I couldn't find where the MenuItem had a MouseDown event...are you sure. > Also, if you are "letting go of the object" by setting it to nothing or > disposing it, you can no longer show it in the Menu bar or Context Menu > PopUp, or whatever. What do you mean by "letting go"? If you can display > it, it's still there and you should be able to get to it's events. > > "Terry Olsen" wrote: > >> I've found a way using the MouseDown event for the MenuItem. However, I >> have dynamically created menu items where I create MenuItem object, add >> it >> to the MenuBar, and then let go of the object. So without the object, I >> can't catch the right-click event. I guess I've got to come up with a >> way >> to hang on to each dynamically created MenuItem object so I can catch the >> right-click and remove the item from the MenuBar. >> >> "Howard Kaikow" <kaikow@standards.com> wrote in message >> news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... >> > "Adam Goossens" <adam.goossens@gmail.com> wrote in message >> > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... >> >> Hi Terry, >> >> >> >> To my knowledge there isn't a way to determine whether a click on a >> >> menu >> >> item was a right or a left click (well, probably no simple way). >> > >> > There must be some way as Word has a DocumentBeforeRightClickEvent. >> > Dunno how it works internally. >> > >> > >> >> >>
That's the Click event, not the mousedown event. Also, the MenuItem is still accessable as a menuitem in the FavoritesToolStripMenuItem.DropDownItems collections, i.e. FavoritesToolStripMenuItem.DropDownItems(0) or 1 or whatever. I also didn't find the DropDownItems Property/Method for any control...what type is used to instantiate the instance of FavoritesToolStripMenuItem? Are you using a custom third party control? [quoted text, click to view] "Terry Olsen" wrote: > The following routine is what I use to add the MenuItem to a menu. As you > can see, the scope of the object is local to the Subroutine, so once I leave > the routine, I no longer have access to it, but it has been added to the > menubar so it continues to display and I can click on it and respond to it > using the 2nd routine listed below. The only way I can figure out how to > catch a right-click is to make a global array of MenuItems and add event > handlers for each one. Then I'll be able to respond to MouseDown events. > > Sub AddFavoriteToMenu(ByVal FavoriteName As String) > > Dim MenuItem As New ToolStripMenuItem > > MenuItem.Text = FavoriteName > > FavoritesToolStripMenuItem.DropDownItems.Add(MenuItem) > > End Sub > > Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByVal sender As > Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) > Handles FavoritesToolStripMenuItem.DropDownItemClicked > > Dim tmp As String = e.ClickedItem.ToString > > If tmp = "A&dd" Then Exit Sub > > FavoriteMenuItemClicked(e.ClickedItem.ToString) > > End Sub > > "Dennis" <Dennis@discussions.microsoft.com> wrote in message > news:9F6B790E-8124-443C-99EE-362ED73CA83F@microsoft.com... > >I couldn't find where the MenuItem had a MouseDown event...are you sure. > > Also, if you are "letting go of the object" by setting it to nothing or > > disposing it, you can no longer show it in the Menu bar or Context Menu > > PopUp, or whatever. What do you mean by "letting go"? If you can display > > it, it's still there and you should be able to get to it's events. > > > > "Terry Olsen" wrote: > > > >> I've found a way using the MouseDown event for the MenuItem. However, I > >> have dynamically created menu items where I create MenuItem object, add > >> it > >> to the MenuBar, and then let go of the object. So without the object, I > >> can't catch the right-click event. I guess I've got to come up with a > >> way > >> to hang on to each dynamically created MenuItem object so I can catch the > >> right-click and remove the item from the MenuBar. > >> > >> "Howard Kaikow" <kaikow@standards.com> wrote in message > >> news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... > >> > "Adam Goossens" <adam.goossens@gmail.com> wrote in message > >> > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... > >> >> Hi Terry, > >> >> > >> >> To my knowledge there isn't a way to determine whether a click on a > >> >> menu > >> >> item was a right or a left click (well, probably no simple way). > >> > > >> > There must be some way as Word has a DocumentBeforeRightClickEvent. > >> > Dunno how it works internally. > >> > > >> > > >> > >> > >> > >
Exactly. The click event is the only thing I have access to using the FavoritesToolStripMenuItem.DropDownItems_Click handler. I can only see which item under FavoritesToolStripMenuItem that I've clicked on, not whether it was a right or left click (in fact, the event doesn't even trigger to a right-click). If I look at a MenuItem that was added at design time, then I have access to the MouseDown event where I can catch the right-click event. My problem is that I need to catch the MouseDown event for the dynamically added MenuItems, then I can pull the right-click out of that. [quoted text, click to view] "Dennis" <Dennis@discussions.microsoft.com> wrote in message news:A3DFC3CA-132E-410F-BA4E-7E019DB39098@microsoft.com... > That's the Click event, not the mousedown event. Also, the MenuItem is > still > accessable as a menuitem in the FavoritesToolStripMenuItem.DropDownItems > collections, i.e. FavoritesToolStripMenuItem.DropDownItems(0) or 1 or > whatever. I also didn't find the DropDownItems Property/Method for any > control...what type is used to instantiate the instance of > FavoritesToolStripMenuItem? Are you using a custom third party control? > > "Terry Olsen" wrote: > >> The following routine is what I use to add the MenuItem to a menu. As >> you >> can see, the scope of the object is local to the Subroutine, so once I >> leave >> the routine, I no longer have access to it, but it has been added to the >> menubar so it continues to display and I can click on it and respond to >> it >> using the 2nd routine listed below. The only way I can figure out how to >> catch a right-click is to make a global array of MenuItems and add event >> handlers for each one. Then I'll be able to respond to MouseDown events. >> >> Sub AddFavoriteToMenu(ByVal FavoriteName As String) >> >> Dim MenuItem As New ToolStripMenuItem >> >> MenuItem.Text = FavoriteName >> >> FavoritesToolStripMenuItem.DropDownItems.Add(MenuItem) >> >> End Sub >> >> Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByVal sender >> As >> Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) >> Handles FavoritesToolStripMenuItem.DropDownItemClicked >> >> Dim tmp As String = e.ClickedItem.ToString >> >> If tmp = "A&dd" Then Exit Sub >> >> FavoriteMenuItemClicked(e.ClickedItem.ToString) >> >> End Sub >> >> "Dennis" <Dennis@discussions.microsoft.com> wrote in message >> news:9F6B790E-8124-443C-99EE-362ED73CA83F@microsoft.com... >> >I couldn't find where the MenuItem had a MouseDown event...are you sure. >> > Also, if you are "letting go of the object" by setting it to nothing or >> > disposing it, you can no longer show it in the Menu bar or Context Menu >> > PopUp, or whatever. What do you mean by "letting go"? If you can >> > display >> > it, it's still there and you should be able to get to it's events. >> > >> > "Terry Olsen" wrote: >> > >> >> I've found a way using the MouseDown event for the MenuItem. However, >> >> I >> >> have dynamically created menu items where I create MenuItem object, >> >> add >> >> it >> >> to the MenuBar, and then let go of the object. So without the object, >> >> I >> >> can't catch the right-click event. I guess I've got to come up with a >> >> way >> >> to hang on to each dynamically created MenuItem object so I can catch >> >> the >> >> right-click and remove the item from the MenuBar. >> >> >> >> "Howard Kaikow" <kaikow@standards.com> wrote in message >> >> news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... >> >> > "Adam Goossens" <adam.goossens@gmail.com> wrote in message >> >> > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... >> >> >> Hi Terry, >> >> >> >> >> >> To my knowledge there isn't a way to determine whether a click on a >> >> >> menu >> >> >> item was a right or a left click (well, probably no simple way). >> >> > >> >> > There must be some way as Word has a DocumentBeforeRightClickEvent. >> >> > Dunno how it works internally. >> >> > >> >> > >> >> >> >> >> >> >> >> >>
I don't see the mousedown event in the MenuItem Class...are you sure it has a MouseDown event..all I saw was the Click Event for this class. [quoted text, click to view] "Terry Olsen" wrote: > Exactly. The click event is the only thing I have access to using the > FavoritesToolStripMenuItem.DropDownItems_Click handler. I can only see > which item under FavoritesToolStripMenuItem that I've clicked on, not > whether it was a right or left click (in fact, the event doesn't even > trigger to a right-click). If I look at a MenuItem that was added at design > time, then I have access to the MouseDown event where I can catch the > right-click event. My problem is that I need to catch the MouseDown event > for the dynamically added MenuItems, then I can pull the right-click out of > that. > > "Dennis" <Dennis@discussions.microsoft.com> wrote in message > news:A3DFC3CA-132E-410F-BA4E-7E019DB39098@microsoft.com... > > That's the Click event, not the mousedown event. Also, the MenuItem is > > still > > accessable as a menuitem in the FavoritesToolStripMenuItem.DropDownItems > > collections, i.e. FavoritesToolStripMenuItem.DropDownItems(0) or 1 or > > whatever. I also didn't find the DropDownItems Property/Method for any > > control...what type is used to instantiate the instance of > > FavoritesToolStripMenuItem? Are you using a custom third party control? > > > > "Terry Olsen" wrote: > > > >> The following routine is what I use to add the MenuItem to a menu. As > >> you > >> can see, the scope of the object is local to the Subroutine, so once I > >> leave > >> the routine, I no longer have access to it, but it has been added to the > >> menubar so it continues to display and I can click on it and respond to > >> it > >> using the 2nd routine listed below. The only way I can figure out how to > >> catch a right-click is to make a global array of MenuItems and add event > >> handlers for each one. Then I'll be able to respond to MouseDown events. > >> > >> Sub AddFavoriteToMenu(ByVal FavoriteName As String) > >> > >> Dim MenuItem As New ToolStripMenuItem > >> > >> MenuItem.Text = FavoriteName > >> > >> FavoritesToolStripMenuItem.DropDownItems.Add(MenuItem) > >> > >> End Sub > >> > >> Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByVal sender > >> As > >> Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) > >> Handles FavoritesToolStripMenuItem.DropDownItemClicked > >> > >> Dim tmp As String = e.ClickedItem.ToString > >> > >> If tmp = "A&dd" Then Exit Sub > >> > >> FavoriteMenuItemClicked(e.ClickedItem.ToString) > >> > >> End Sub > >> > >> "Dennis" <Dennis@discussions.microsoft.com> wrote in message > >> news:9F6B790E-8124-443C-99EE-362ED73CA83F@microsoft.com... > >> >I couldn't find where the MenuItem had a MouseDown event...are you sure. > >> > Also, if you are "letting go of the object" by setting it to nothing or > >> > disposing it, you can no longer show it in the Menu bar or Context Menu > >> > PopUp, or whatever. What do you mean by "letting go"? If you can > >> > display > >> > it, it's still there and you should be able to get to it's events. > >> > > >> > "Terry Olsen" wrote: > >> > > >> >> I've found a way using the MouseDown event for the MenuItem. However, > >> >> I > >> >> have dynamically created menu items where I create MenuItem object, > >> >> add > >> >> it > >> >> to the MenuBar, and then let go of the object. So without the object, > >> >> I > >> >> can't catch the right-click event. I guess I've got to come up with a > >> >> way > >> >> to hang on to each dynamically created MenuItem object so I can catch > >> >> the > >> >> right-click and remove the item from the MenuBar. > >> >> > >> >> "Howard Kaikow" <kaikow@standards.com> wrote in message > >> >> news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... > >> >> > "Adam Goossens" <adam.goossens@gmail.com> wrote in message > >> >> > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... > >> >> >> Hi Terry, > >> >> >> > >> >> >> To my knowledge there isn't a way to determine whether a click on a > >> >> >> menu > >> >> >> item was a right or a left click (well, probably no simple way). > >> >> > > >> >> > There must be some way as Word has a DocumentBeforeRightClickEvent. > >> >> > Dunno how it works internally. > >> >> > > >> >> > > >> >> > >> >> > >> >> > >> > >> > >> > >
Let me double-check what I've got...we may be talking about different things here... [quoted text, click to view] "Dennis" <Dennis@discussions.microsoft.com> wrote in message news:5C364C7B-D83B-4F88-BF63-0850CA512DD9@microsoft.com... >I don't see the mousedown event in the MenuItem Class...are you sure it has >a > MouseDown event..all I saw was the Click Event for this class. > > "Terry Olsen" wrote: > >> Exactly. The click event is the only thing I have access to using the >> FavoritesToolStripMenuItem.DropDownItems_Click handler. I can only see >> which item under FavoritesToolStripMenuItem that I've clicked on, not >> whether it was a right or left click (in fact, the event doesn't even >> trigger to a right-click). If I look at a MenuItem that was added at >> design >> time, then I have access to the MouseDown event where I can catch the >> right-click event. My problem is that I need to catch the MouseDown >> event >> for the dynamically added MenuItems, then I can pull the right-click out >> of >> that. >> >> "Dennis" <Dennis@discussions.microsoft.com> wrote in message >> news:A3DFC3CA-132E-410F-BA4E-7E019DB39098@microsoft.com... >> > That's the Click event, not the mousedown event. Also, the MenuItem is >> > still >> > accessable as a menuitem in the >> > FavoritesToolStripMenuItem.DropDownItems >> > collections, i.e. FavoritesToolStripMenuItem.DropDownItems(0) or 1 or >> > whatever. I also didn't find the DropDownItems Property/Method for any >> > control...what type is used to instantiate the instance of >> > FavoritesToolStripMenuItem? Are you using a custom third party >> > control? >> > >> > "Terry Olsen" wrote: >> > >> >> The following routine is what I use to add the MenuItem to a menu. As >> >> you >> >> can see, the scope of the object is local to the Subroutine, so once I >> >> leave >> >> the routine, I no longer have access to it, but it has been added to >> >> the >> >> menubar so it continues to display and I can click on it and respond >> >> to >> >> it >> >> using the 2nd routine listed below. The only way I can figure out how >> >> to >> >> catch a right-click is to make a global array of MenuItems and add >> >> event >> >> handlers for each one. Then I'll be able to respond to MouseDown >> >> events. >> >> >> >> Sub AddFavoriteToMenu(ByVal FavoriteName As String) >> >> >> >> Dim MenuItem As New ToolStripMenuItem >> >> >> >> MenuItem.Text = FavoriteName >> >> >> >> FavoritesToolStripMenuItem.DropDownItems.Add(MenuItem) >> >> >> >> End Sub >> >> >> >> Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByVal >> >> sender >> >> As >> >> Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) >> >> Handles FavoritesToolStripMenuItem.DropDownItemClicked >> >> >> >> Dim tmp As String = e.ClickedItem.ToString >> >> >> >> If tmp = "A&dd" Then Exit Sub >> >> >> >> FavoriteMenuItemClicked(e.ClickedItem.ToString) >> >> >> >> End Sub >> >> >> >> "Dennis" <Dennis@discussions.microsoft.com> wrote in message >> >> news:9F6B790E-8124-443C-99EE-362ED73CA83F@microsoft.com... >> >> >I couldn't find where the MenuItem had a MouseDown event...are you >> >> >sure. >> >> > Also, if you are "letting go of the object" by setting it to nothing >> >> > or >> >> > disposing it, you can no longer show it in the Menu bar or Context >> >> > Menu >> >> > PopUp, or whatever. What do you mean by "letting go"? If you can >> >> > display >> >> > it, it's still there and you should be able to get to it's events. >> >> > >> >> > "Terry Olsen" wrote: >> >> > >> >> >> I've found a way using the MouseDown event for the MenuItem. >> >> >> However, >> >> >> I >> >> >> have dynamically created menu items where I create MenuItem object, >> >> >> add >> >> >> it >> >> >> to the MenuBar, and then let go of the object. So without the >> >> >> object, >> >> >> I >> >> >> can't catch the right-click event. I guess I've got to come up >> >> >> with a >> >> >> way >> >> >> to hang on to each dynamically created MenuItem object so I can >> >> >> catch >> >> >> the >> >> >> right-click and remove the item from the MenuBar. >> >> >> >> >> >> "Howard Kaikow" <kaikow@standards.com> wrote in message >> >> >> news:%23InNlodPFHA.1932@tk2msftngp13.phx.gbl... >> >> >> > "Adam Goossens" <adam.goossens@gmail.com> wrote in message >> >> >> > news:eOmCPbaPFHA.3292@TK2MSFTNGP12.phx.gbl... >> >> >> >> Hi Terry, >> >> >> >> >> >> >> >> To my knowledge there isn't a way to determine whether a click >> >> >> >> on a >> >> >> >> menu >> >> >> >> item was a right or a left click (well, probably no simple way). >> >> >> > >> >> >> > There must be some way as Word has a >> >> >> > DocumentBeforeRightClickEvent. >> >> >> > Dunno how it works internally. >> >> >> > >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
Don't see what you're looking for? Try a search.
|
|
|