473,775 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to extract the Click event from tsMenuItem.Even ts

newItem and tsMenuItem are ToolStripMenuIt ems.

I'd like to add the click event in tsMenuItem to newItem.

Can't do this because Events is Protected:

newItem.Events. AddHandlers(tsM enuItem.Events) ;

Can't do this because Click must be on the left side:

newItem.Click += tsMenuItem.Clic k;

Is there some way I can extract the Click event from tsMenuItem.Even ts so
that I can do this:

newItem.Click += ??

Thanks in advance
Apr 1 '08 #1
11 1396
On Tue, 01 Apr 2008 12:26:42 -0700, AAaron123 <aa*******@road runner.com>
wrote:
newItem and tsMenuItem are ToolStripMenuIt ems.

I'd like to add the click event in tsMenuItem to newItem.
So you want the tsMenuItem.Clic k event handlers to be called in response
to a Click event on newItem?

What about this:

newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.Perf ormClick(); };

Pete
Apr 1 '08 #2
Well, now I have my collection of code that doesn't work and your statement
that does.

I'm quite new to C#. Could you add a few words about the syntax and how it
works.

I not sure if you are defining a Delagate or declaring one.
Thanks very much
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Tue, 01 Apr 2008 12:26:42 -0700, AAaron123 <aa*******@road runner.com>
wrote:
newItem and tsMenuItem are ToolStripMenuIt ems.

I'd like to add the click event in tsMenuItem to newItem.
So you want the tsMenuItem.Clic k event handlers to be called in response
to a Click event on newItem?

What about this:

newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.Perf ormClick(); };

Pete
Apr 1 '08 #3
On Tue, 01 Apr 2008 15:04:35 -0700, AAaron123 <aa*******@road runner.com>
wrote:
Well, now I have my collection of code that doesn't work and your
statement
that does.

I'm quite new to C#. Could you add a few words about the syntax and how
it
works.

I not sure if you are defining a Delagate or declaring one.
Sure. It seems to me that the terms "defining" and "declaring" are not
sufficiently unambiguous. However, in this case the delegate type is
already defined (it's the type used by the Click event, which is
EventHandler), and you are declaring an anonymous method to be used to
create the delegate instance added to the Click event.

As the name suggests, it's basically a method without a name. You could
do the exact same thing by writing a named method that calls
"tsMenuItem.Per formClick()", and adding that named to the event instead.
For example, a method like this:

void ClickRedirect(o bject sender, EventArgs e)
{
tsMenuItem.Perf ormClick();
}

and then elsewhere a line of code that looks like:

newItem.Click += ClickRedirect;

Using the anonymous method allows the code to be more self-contained IMHO,
but otherwise it's more a matter of preference, at least in this
particular situation.

Pete
Apr 1 '08 #4

The trouble I'm having is that if I look at the methods and constructors I
can't find one that fits:
newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.Perf ormClick(); };

Thanks again

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Tue, 01 Apr 2008 15:04:35 -0700, AAaron123 <aa*******@road runner.com>
wrote:
Well, now I have my collection of code that doesn't work and your
statement
that does.

I'm quite new to C#. Could you add a few words about the syntax and how
it
works.

I not sure if you are defining a Delagate or declaring one.
Sure. It seems to me that the terms "defining" and "declaring" are not
sufficiently unambiguous. However, in this case the delegate type is
already defined (it's the type used by the Click event, which is
EventHandler), and you are declaring an anonymous method to be used to
create the delegate instance added to the Click event.

As the name suggests, it's basically a method without a name. You could
do the exact same thing by writing a named method that calls
"tsMenuItem.Per formClick()", and adding that named to the event instead.
For example, a method like this:

void ClickRedirect(o bject sender, EventArgs e)
{
tsMenuItem.Perf ormClick();
}

and then elsewhere a line of code that looks like:

newItem.Click += ClickRedirect;

Using the anonymous method allows the code to be more self-contained IMHO,
but otherwise it's more a matter of preference, at least in this
particular situation.

Pete
Apr 2 '08 #5
(my apologies for the late reply...I only just now noticed that this
message, along with five others, somehow got stuck in my Outbox)

On Wed, 02 Apr 2008 05:19:58 -0700, AAaron123 <aa*******@road runner.com>
wrote:
The trouble I'm having is that if I look at the methods and constructors
I
can't find one that fits:
newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.Perf ormClick(); };
I don't know what that means. Are you trying to find a method or
constructor named "delegate"? If so, you're right...you're not going to
find it.

The word "delegate" is a C# keyword. In one context, it is used to
declare a new delegate type. But in the above context, it's used to
declare an anonymous method. By definition, the anonymous method has no
name and so you won't find it listed in any list of methods.

Pete
Apr 9 '08 #6
I understand: anonymous method

I would like to read about the statement
delegate(object sender, EventArgs e) { tsMenuItem.Perf ormClick(); };

I can see it doesn't fit the format of a declaration (which you verify
below)
Nor that of a Delegate Constructor

You see what I mean? I look at MSDN library and can't find a format that
fits your construction.
Thanks


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
(my apologies for the late reply...I only just now noticed that this
message, along with five others, somehow got stuck in my Outbox)

On Wed, 02 Apr 2008 05:19:58 -0700, AAaron123 <aa*******@road runner.com>
wrote:
The trouble I'm having is that if I look at the methods and constructors
I
can't find one that fits:
newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.Perf ormClick(); };
I don't know what that means. Are you trying to find a method or
constructor named "delegate"? If so, you're right...you're not going to
find it.

The word "delegate" is a C# keyword. In one context, it is used to
declare a new delegate type. But in the above context, it's used to
declare an anonymous method. By definition, the anonymous method has no
name and so you won't find it listed in any list of methods.

Pete
Jun 27 '08 #7
On Sat, 12 Apr 2008 01:39:58 -0700, AAaron123 <aa*******@road runner.com>
wrote:
I understand: anonymous method
Are you sure? :)
I would like to read about the statement
delegate(object sender, EventArgs e) { tsMenuItem.Perf ormClick(); };

I can see it doesn't fit the format of a declaration (which you verify
below)
Nor that of a Delegate Constructor
I don't see how you can understand "anonymous method" but not understand
the expression you're asking about. I can only conclude that you're
mistaken about understanding "anonymous method". So, I'll recommend that
you read this page:
http://msdn2.microsoft.com/en-us/library/0yw3tz5k.aspx

And as well, look around in related sections. The above page is the
section on anonymous methods from the C# Programming Guide. The very
first code example on that page is basically the same as what I posted.

Pete
Jun 27 '08 #8

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Sat, 12 Apr 2008 01:39:58 -0700, AAaron123 <aa*******@road runner.com>
wrote:
>I understand: anonymous method

Are you sure? :)
No, but I thought that if Foo was a function that returned a string
"anonymous" would apply if I wrote
Console.Writeli ne(Foo);
Is that not true?

Anyway, I appreciate the pointer to the site.
That explained a lot.
thanks

>
>I would like to read about the statement
delegate(objec t sender, EventArgs e) { tsMenuItem.Perf ormClick(); };

I can see it doesn't fit the format of a declaration (which you verify
below)
Nor that of a Delegate Constructor

I don't see how you can understand "anonymous method" but not understand
the expression you're asking about. I can only conclude that you're
mistaken about understanding "anonymous method". So, I'll recommend that
you read this page:
http://msdn2.microsoft.com/en-us/library/0yw3tz5k.aspx

And as well, look around in related sections. The above page is the
section on anonymous methods from the C# Programming Guide. The very
first code example on that page is basically the same as what I posted.

Pete

Jun 27 '08 #9
On Sat, 12 Apr 2008 16:45:14 -0700, AAaron123 <aa*******@road runner.com>
wrote:
No, but I thought that if Foo was a function that returned a string
"anonymous" would apply if I wrote
Console.Writeli ne(Foo);
Is that not true?
That's not true. Ignoring for the moment that if Foo is a function (i.e.
"method"), writing "Console.WriteL ine(Foo);" doesn't make sense... The
method "Foo" has a name. Something with a name isn't anonymous, by
definition.

An anonymous method is a method without a name. You create one using the
"delegate" key word, as shown in my code example and as shown in the
documentation to which I refer you.
Anyway, I appreciate the pointer to the site.
That explained a lot.
Glad it helped. :)

Pete
Jun 27 '08 #10

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

Similar topics

2
9756
by: Paolo Mancini | last post by:
Hi all, I have a page with many different elements: <a href="...."> ... </a>, listboxes, radiobuttons, etc. Can I use javascript to prevent the user from interacting with the page? That is: can I intercept, alert the user, and cancel any click event on the page? Unfortunately, if the user clicks on a page element, the event bubbles
8
2324
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta) My app (an image viewer) opens with a Main form with a file explorer if you open the program with the exe, but opens with the ImageView form if you double click an image file, if you want to see the Main form once the ImageView is open the...
4
1477
by: Rochdi | last post by:
Hi guys, I'm using the VS 2002 version and for a TextBox, I've selected the Textbox control from the left combo in the code page and I've seen many events but I couldn't find the Click, GotFocus or LostFocus events like in VB6, and if I type the event like: Private Sub TextBox1_Click(.......)TextBox1.Click End Sub it is working!!! So how can I be able to see the Click, GotFocus or LostFocus events in the right combo box..!!?
0
2956
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
10
2847
by: Peter Michaux | last post by:
Hi, Today I have been testing the event models from Netscape 4.8 and IE 4 to the current crop of browsers. I'd like to write a small event library similar in purpose to the Yahoo! UI event library but with less features and code. The Yahoo! event library is one of the best libraries in YUI but it still seems to me to have some confused code...that or I'm still confused. The Yahoo! UI library focuses on using addEventListener and
4
6225
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for Struts: import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator;
1
2561
by: andy.hume | last post by:
Hello, Is there any cross-browser method of determining whether a click event was triggered by a mouse left click or the keyboard's 'enter' key? I was expecting event.button, or event.which to be able to do this, but this doesn't seem to be the case. Checking event.clientX == 0 && event.clientY == 0 works in FF, but not in IE. Anything else I can try?
11
1487
by: darrel | last post by:
Trying to get back into .net again after being out of it for a while. I'm trying to figure out the proper way to handle multiple events via a try catch. What I'm confused about is the proper method to handle, say, 3 separate events: A, B, and C. I only want all 3 to execute if all 3 can successfully execute. Is that what a try-catch is for, or is a try/catch mainly for individual
4
1687
by: SpreadTooThin | last post by:
I'm running Visual Basic Express Editon 2008. I have a project that references an OLE object called MyObject That object fires events. How do I declare the event handler in the Main Form class implementation? Public Class Form1 Dim WithEvents server as MyObject.MyServer
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9915
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.