473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Raising events from a custom class

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
Nov 16 '05 #1
4 1472
Sounds like the same model Darren is using for his Asynchronous BO model.

http://markitup.aspxconnection.com/P...x?projectId=28

Gave him the idea a while back and while the example is not exactly what you are
looking for below, it has all of the features you are looking for.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"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

Nov 16 '05 #2
Landley <ne**@creations-software.co.uk> wrote:
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


I just went through this myself. I found Microsoft's example to be the
most helpful after searching the web. It's nearly what you want plus
a bit of fat.

http://tinyurl.com/5qdwu

Nov 16 '05 #3
Thanks for your help.

I think I have been wrapped in cotton wool during my VB6 and VB.NET years.
Events and event handling are so easy to create and manipulate. C# seems so
long winded. I'll hang in there, as when I become more familiar with the
strategies, I am sure that I will be more enthusiatic about it.

"Brian" <be@rohan.sdsu.edu> wrote in message
news:cm**********@gondor.sdsu.edu...
Landley <ne**@creations-software.co.uk> wrote:
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


I just went through this myself. I found Microsoft's example to be the
most helpful after searching the web. It's nearly what you want plus
a bit of fat.

http://tinyurl.com/5qdwu

Nov 16 '05 #4
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

Nov 16 '05 #5

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

Similar topics

4
by: serge calderara | last post by:
Dear all, I have a class wich is raising events as normally it should do. having a form in the same assembly wich is catching those events works fne. Raise events gets catch normaly within the...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
0
by: Robert Brinson | last post by:
I have created a custom TextBox by inheriting TextBox. My purpose in this was so that I could raise a BubleEvent such that custom TextBoxes that are child controls of a DataGrid would actually...
1
by: Martin | last post by:
Hi, I have been having trouble rasing events in my custom (composite) server controls. To demonstate my problem I put a small control together with a single button on it and included the code...
0
by: BenLeino | last post by:
Hi out there, I have a little problem with threading an event receiving. I have a custom Class (DLL) that raises Events. When I run the Instance without threading it works fine. When I do...
4
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written...
2
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on...
1
by: Asko Telinen | last post by:
Hi all. I ran into quite strange problem concerning the event raising inside FileSystemWatcher Delete event. First, i would like to describe a bit my environment. I have main GUI...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.