473,385 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to catch a right-click

How can I catch a right-click on a DropDownMenuItem?
Nov 21 '05 #1
11 2549
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

"Terry Olsen" wrote:
How can I catch a right-click on a DropDownMenuItem?

Nov 21 '05 #2
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?

Nov 21 '05 #3
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.

"Adam Goossens" <ad***********@gmail.com> wrote in message
news:eO**************@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?

Nov 21 '05 #4
"Adam Goossens" <ad***********@gmail.com> wrote in message
news:eO**************@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.
Nov 21 '05 #5
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" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Adam Goossens" <ad***********@gmail.com> wrote in message
news:eO**************@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.

Nov 21 '05 #6
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" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Adam Goossens" <ad***********@gmail.com> wrote in message
news:eO**************@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.


Nov 21 '05 #7
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(MenuI tem)

End Sub

Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByV al 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" <De****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.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" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> "Adam Goossens" <ad***********@gmail.com> wrote in message
> news:eO**************@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.
>
>


Nov 21 '05 #8
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(MenuI tem)

End Sub

Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByV al 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" <De****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.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" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> "Adam Goossens" <ad***********@gmail.com> wrote in message
> news:eO**************@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.
>
>


Nov 21 '05 #9
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" <De****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.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(MenuI tem)

End Sub

Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByV al 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" <De****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.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" <ka****@standards.com> wrote in message
>> news:%2****************@tk2msftngp13.phx.gbl...
>> > "Adam Goossens" <ad***********@gmail.com> wrote in message
>> > news:eO**************@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.
>> >
>> >
>>
>>
>>


Nov 21 '05 #10
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" <De****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.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(MenuI tem)

End Sub

Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByV al 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" <De****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.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" <ka****@standards.com> wrote in message
>> news:%2****************@tk2msftngp13.phx.gbl...
>> > "Adam Goossens" <ad***********@gmail.com> wrote in message
>> > news:eO**************@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.
>> >
>> >
>>
>>
>>


Nov 21 '05 #11
Let me double-check what I've got...we may be talking about different things
here...
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.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" <De****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.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(MenuI tem)
>>
>> End Sub
>>
>> Private Sub FavoritesToolStripMenuItem_DropDownItemClicked(ByV al
>> 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" <De****@discussions.microsoft.com> wrote in message
>> news:9F**********************************@microsof t.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" <ka****@standards.com> wrote in message
>> >> news:%2****************@tk2msftngp13.phx.gbl...
>> >> > "Adam Goossens" <ad***********@gmail.com> wrote in message
>> >> > news:eO**************@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.
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
by: John | last post by:
Hello I know this is extremely basic, I just want to make sure I got it right. is: try{} catch{} the same as try{}
4
by: Abhishek Srivastava | last post by:
Hello All, I have seen code snippets like try { ..... } catch {
8
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
18
by: Simon | last post by:
I was of the impression that code placed after a Try...Catch block was only executed if there was no exception thrown. I've got some VB.net code as part of a Windows form that executes even...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
13
by: Bit byte | last post by:
Is there any way of retrievieng error information (say, from a 'global' or system wide) error object - when you are in a catch all statement block? Sometimes it cannot be helped, when something...
7
by: tommaso.gastaldi | last post by:
It would be useful, sometimes, when debugging, to disable all the try /catch one has in the program (clearly not commenting them out). Any info or hint on that? -tom
4
by: Jeff Jarrell | last post by:
I have a block of code that during development is prone to casting errors. It is mostly a DataReader type thing. It looks something like this. _prtPNID = myDLReader.GetString("prtPNID")...
6
by: rhaazy | last post by:
I am looking for some feedback on using try catch statements. Usually when I start a project I use them for everything, but stop using them as often after the "meat n' potatos" of the project is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.