MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get events assigned to ToolStripMenuItem.Click

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp
Author Message
Academia



Joined: 28 Sep 2007
Posts: 40

PostPosted: Thu Feb 28, 2008 1:39 am    Post subject: How to get events assigned to ToolStripMenuItem.Click Reply with quote

In the code below I

Call CopyToolStripMenuItem which effectively copies the properties of
saveToolStripMenuItem one at a time into newItem.

The next statement changes the Text of newItem to "New"

The next statement adds newItem to the DropDownItems.

Finally I assign an event to newItem.Click.

But what I really want to assign to newItem.Click is whatever is assigned to
saveToolStripMenuItem.Click

Do you know how to do that?



Thanks



ToolStripMenuItem newItem;

newItem = CloneToolStripMenuItem(saveToolStripMenuItem);

newItem.Text="New";

this.fileToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {

newItem});

newItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);

Archived from group: microsoft>public>dotnet>languages>csharp
Back to top
View user's profile Send private message
Peter Duniho



Joined: 08 Aug 2007
Posts: 45

PostPosted: Wed Feb 27, 2008 11:52 pm    Post subject: Re: How to get events assigned to ToolStripMenuItem.Click Reply with quote

On Wed, 27 Feb 2008 17:39:42 -0800, Academia
wrote:

> In the code below I
>
> Call CopyToolStripMenuItem which effectively copies the properties of
> saveToolStripMenuItem one at a time into newItem.
>
> The next statement changes the Text of newItem to "New"
>
> The next statement adds newItem to the DropDownItems.
>
> Finally I assign an event to newItem.Click.
>
> But what I really want to assign to newItem.Click is whatever is
> assigned to
> saveToolStripMenuItem.Click
>
> Do you know how to do that?

As far as I know, the only way to do that is to subclass ToolStripItem (or
ToolStripMenuItem) and provide a property or method that exposes that
information. Even then, you would have to implement a new event, rather
than using the existing Click event, as the auto-generated field used by
the Click event would be private and inaccessible to your sub-class.

Of course, if you do make a sub-class, you could implement a Clone()
method too, which would make that "CloneToolStripMenuItem()" method a
little nicer to use. Smile

For what it's worth, you could track the subscribers elsewhere. For
example, you could use the Tag property to keep track of who's subscribed
to the event. It'd be a pain, and would be fragile, as you'd have to make
sure you always updated the property any time you subscribed or
unsubscribed from the Click event. But it could be done.

I think it's kind of too bad that the events in the Control class aren't
virtual. It would be nice to be able to override their default behavior,
for situations like this.

Pete

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Extending ToolStripMenuItem. Need help with designer. I am extending the class to provide some base functionality in my application. However, this control will be used by consultants and I need to make it accessible through the designer. To be clear, I need to allow them to drop a MenuStrip

Single click / double click I am writing a forms program with a notify icon in the system tray. I have event handlers for both OnClick and However, when you double click on the icon, it fires the OnClick event as well. I tried implementing this through a OnMouseUp eve

Right-click menu Hi All Is it possible to program my VB 6 app so that when a user right-clicks on a label at run time it brings up a floating menu (is this a contextual one?) with a list of pre-defined options and when the user selects one of these options I can then pass

Button click single Hi, I have been creating an Button using .Net C#. Once the user clicks the button, the click event handler will perform task A. This normally takes around 2 minutes. During this 2 minutes, the user must not be allowed to click this button again. However,

Make a window "Click-through" Hello everyone, I've got two little apps which are able to create a window that displays something on the desktop, but are not clickable. Instead, when you click on the window, the item 'behind' or 'under' that window gets clicked. I'd like to know how t
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group