newItem and tsMenuItem are ToolStripMenuItems.
I'd like to add the click event in tsMenuItem to newItem.
Can't do this because Events is Protected:
newItem.Events.AddHandlers(tsMenuItem.Events);
Can't do this because Click must be on the left side:
newItem.Click += tsMenuItem.Click;
Is there some way I can extract the Click event from tsMenuItem.Events so
that I can do this:
newItem.Click += ??
Thanks in advance 11 1363
On Tue, 01 Apr 2008 12:26:42 -0700, AAaron123 <aa*******@roadrunner.com>
wrote:
newItem and tsMenuItem are ToolStripMenuItems.
I'd like to add the click event in tsMenuItem to newItem.
So you want the tsMenuItem.Click event handlers to be called in response
to a Click event on newItem?
What about this:
newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.PerformClick(); };
Pete
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*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Tue, 01 Apr 2008 12:26:42 -0700, AAaron123 <aa*******@roadrunner.com>
wrote:
newItem and tsMenuItem are ToolStripMenuItems.
I'd like to add the click event in tsMenuItem to newItem.
So you want the tsMenuItem.Click event handlers to be called in response
to a Click event on newItem?
What about this:
newItem.Click += delegate(object sender, EventArgs e)
{ tsMenuItem.PerformClick(); };
Pete
On Tue, 01 Apr 2008 15:04:35 -0700, AAaron123 <aa*******@roadrunner.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.PerformClick()", and adding that named to the event instead.
For example, a method like this:
void ClickRedirect(object sender, EventArgs e)
{
tsMenuItem.PerformClick();
}
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
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.PerformClick(); };
Thanks again
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Tue, 01 Apr 2008 15:04:35 -0700, AAaron123 <aa*******@roadrunner.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.PerformClick()", and adding that named to the event instead.
For example, a method like this:
void ClickRedirect(object sender, EventArgs e)
{
tsMenuItem.PerformClick();
}
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
(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*******@roadrunner.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.PerformClick(); };
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
I understand: anonymous method
I would like to read about the statement
delegate(object sender, EventArgs e) { tsMenuItem.PerformClick(); };
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*********@nnowslpianmk.comwrote 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*******@roadrunner.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.PerformClick(); };
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
On Sat, 12 Apr 2008 01:39:58 -0700, AAaron123 <aa*******@roadrunner.com>
wrote:
I understand: anonymous method
Are you sure? :)
I would like to read about the statement
delegate(object sender, EventArgs e) { tsMenuItem.PerformClick(); };
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
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 12 Apr 2008 01:39:58 -0700, AAaron123 <aa*******@roadrunner.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.Writeline(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(object sender, EventArgs e) { tsMenuItem.PerformClick(); };
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
On Sat, 12 Apr 2008 16:45:14 -0700, AAaron123 <aa*******@roadrunner.com>
wrote:
No, but I thought that if Foo was a function that returned a string
"anonymous" would apply if I wrote
Console.Writeline(Foo);
Is that not true?
That's not true. Ignoring for the moment that if Foo is a function (i.e.
"method"), writing "Console.WriteLine(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
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 12 Apr 2008 16:45:14 -0700, AAaron123 <aa*******@roadrunner.com>
wrote:
>No, but I thought that if Foo was a function that returned a string "anonymous" would apply if I wrote Console.Writeline(Foo); Is that not true?
That's not true. Ignoring for the moment that if Foo is a function (i.e.
"method"), writing "Console.WriteLine(Foo);" doesn't make sense... The
method "Foo" has a name. Something with a name isn't anonymous, by
definition.
But the string variable does not have a name.
Thanks for all the help
>
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
"AAaron123" <aa*******@roadrunner.comwrote in message
news:eC**************@TK2MSFTNGP04.phx.gbl...
>
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
>On Sat, 12 Apr 2008 16:45:14 -0700, AAaron123 <aa*******@roadrunner.com> wrote:
>>No, but I thought that if Foo was a function that returned a string "anonymous" would apply if I wrote Console.Writeline(Foo); Is that not true?
That's not true. Ignoring for the moment that if Foo is a function (i.e. "method"), writing "Console.WriteLine(Foo);" doesn't make sense... The method "Foo" has a name. Something with a name isn't anonymous, by definition.
But the string variable does not have a name.
I just had ocassion to read what I said.
I do see the difference between the function return being anonomyous and the
body being anonomous.
Thanks again
>
Thanks for all the help
>> 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:...
|
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)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |