Hi Landley,
It is possible that I didn't understand correctly the problem, but I don't
see any tricky part here
class Bar
{
publuic event FooEventHandler Foo;
public void RaiseFoo(FooEventArgs e)
{
if(Foo != null)
Foo(this, e);
}
}
Now the form can instantiate Bar class and call RiseFoo. whoever has
subscribed will receive the even.
The form has to expose the istance in order the other to subscribe. The next
is thing is the real sender of the event. Reference to it can be embeded in
the event args ot the sender can pass itself to the RaiseFoo method as a
paramter and the the event will be raised on its behalf.
WindowsForm uses similar model on its Control.InvokeOnClick, for example,
where one can make other control to raise Click event.
Other example would be IComponentChangeService and its OnComponentChnagXXX
method that raise ComponentChangXXX events
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Landley" <ne**@creations-software.co.uk> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Hello All,
I am new to C# (and converting from VB.NET).
1. I am trying to create a class that has one method and one event. The
method's sole purpose is to raise the event.
2. ... then instantiate the class from another class (e.g. a Form) and
call
the method on the first class.
3. ... then handle the event raised from the first class.
Simple you say! I haven't come across a simple example of this in any
documentation.
Can you help and prevent me from self harm?!
Landley