Home All Groups Group Topic Archive Search About
Author
29 Nov 2007 9:54 AM
csharpula csharp
Hello,
I want to invoke event in one form which will be sent to other form
(both forms has nothing in common) . Could someone plz refer me to good
example for doing it? Thank you!



*** Sent via Developersdex http://www.developersdex.com ***

Author
29 Nov 2007 12:06 PM
Peter Bromberg [C# MVP]
article here will help:
http://www.eggheadcafe.com/articles/20040229.asp


--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Show quote
"csharpula csharp" wrote:

> Hello,
> I want to invoke event in one form which will be sent to other form
> (both forms has nothing in common) . Could someone plz refer me to good
> example for doing it? Thank you!
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
Author
29 Nov 2007 12:18 PM
Jon Skeet [C# MVP]
On Nov 29, 12:06 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote:
The recommendation of using the "sender" parameter for arbitrary data
seems like a bad idea to me. The sender parameter has a clearly
defined role: it should be the object raising the event. If the event
logically takes arguments (e.g. a message to display) that's what the
second parameter is for.

Jon
Author
29 Nov 2007 5:15 PM
Peter Bromberg [C# MVP]
You are correct, it should be sent in a custom EventArgs - derived class. Old
article.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Show quote
"Jon Skeet [C# MVP]" wrote:

> On Nov 29, 12:06 pm, Peter Bromberg [C# MVP]
> <pbromb...@yahoo.NoSpamMaam.com> wrote:
> > article here will help:http://www.eggheadcafe.com/articles/20040229.asp
>
> The recommendation of using the "sender" parameter for arbitrary data
> seems like a bad idea to me. The sender parameter has a clearly
> defined role: it should be the object raising the event. If the event
> logically takes arguments (e.g. a message to display) that's what the
> second parameter is for.
>
> Jon
>
Author
29 Nov 2007 4:02 PM
csharpula csharp
It is not helping in my case because I need a communication between 2
forms which are not in inheritence relatioship .Hoc can I change value
of one control basing on change that occured on other form? (no
inheritence between forms) Thank you!


*** Sent via Developersdex http://www.developersdex.com ***
Author
29 Nov 2007 4:26 PM
Jon Skeet [C# MVP]
On Nov 29, 4:02 pm, csharpula csharp <csharp***@yahoo.com> wrote:
> It is not helping in my case because I need a communication between 2
> forms which are not in inheritence relatioship

That's irrelevant - why would they need to be in an inheritance
relationship?

One form just needs to publish an event, and the other form needs to
know about the first form.

Jon
Author
29 Nov 2007 6:05 PM
csharpula csharp
The question is how form2 will know about the event if it has no istance
of form 1? (which published it) I am just looking for an example of
event invoking in such case.If someone can send me a link of such
example that will really help. Thank you!

*** Sent via Developersdex http://www.developersdex.com ***
Author
29 Nov 2007 6:19 PM
Andrus
You are right, delegates are useless in WinForms event invoking.

Your forms should implement common interface and use it like

foreach (Form o in this.MdiParent.MdiChildren)

((IMyEvents)o).MyEvent();

Andrus.

Show quote
"csharpula csharp" <csharp***@yahoo.com> kirjutas sõnumis
news:%23DPGmJrMIHA.5208@TK2MSFTNGP04.phx.gbl...
>
>
> The question is how form2 will know about the event if it has no istance
> of form 1? (which published it) I am just looking for an example of
> event invoking in such case.If someone can send me a link of such
> example that will really help. Thank you!
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
29 Nov 2007 6:44 PM
Jon Skeet [C# MVP]
Andrus <kobrule***@hot.ee> wrote:
> You are right, delegates are useless in WinForms event invoking.

Eh? What on earth do you mean by that? Delegates are the whole basis of
events in .NET, including WinForms events.

> Your forms should implement common interface and use it like
>
> foreach (Form o in this.MdiParent.MdiChildren)
>
> ((IMyEvents)o).MyEvent();

Well, at that point it's not really an event in .NET terms - it's just
a plain method.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Author
29 Nov 2007 6:43 PM
Jon Skeet [C# MVP]
csharpula csharp <csharp***@yahoo.com> wrote:
> The question is how form2 will know about the event if it has no istance
> of form 1? (which published it)

Well it will clearly need to know about the instance of form1 in some
way or other, but that has very little to do with inheritance.

You could pass a reference to form1 to the constructor of form2, or
something similar.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Author
29 Nov 2007 10:21 PM
bob
On Thu, 29 Nov 2007 01:54:15 -0800, csharpula csharp
<csharp***@yahoo.com> wrote:

>Hello,
>I want to invoke event in one form which will be sent to other form
>(both forms has nothing in common) . Could someone plz refer me to good
>example for doing it? Thank you!
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
Hi,
Check out my example in reply to your 'Design GUI'  question on 28th
Nov.
regards
Bob

AddThis Social Bookmark Button