473,508 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base and derived event firing in .NET v1

Hi!

Im having real issues understanding delegates/events in .NET v1, and was
hoping someone could shed some light on where I'm not quite understanding.
I've got this piece of code in a base user control, which i've called
'PropertyPanel'. In it is the following code:

public delegate void EventHandler(object sender, EventArgs e);

public event EventHandler AppliedProperties;

private void buttonOK_Click(object sender, System.EventArgs e)

{

EventHandler handler = AppliedProperties;

EventArgs ex = new EventArgs();

if (ValidateForm())

{

if (handler!=null)

{

handler(this, ex);

}

}

}

Now what I'd like to do is to derive from my base user control several other
property panels, but still hook to my AppliedProperties event handler within
the main form, which will fire from a specific implementation within the
derived class, for example by:

(in the main form)

PropertyPanel myPropertyPanel;

myPropertyPanel = new NodePropertyPane();

myPropertyPanel.AppliedProperties += new EventHandler(this.Test);

OR myPropertyPanel = new LinkPropertyPane();

myPropertyPanel.AppliedProperties += ....

Does anyone know or can give me advice how to best go about this?

Any help would be greatly appreciated,

Paul


Jul 27 '06 #1
1 1265
pkiddie,

The problem here is that you are defining the EventHandler delegate in
your class. You also subsequently declare your event of that type. There
are two ways to fix this. The first is to patch up the call site for the
event:

myPropertyPanel.AppliedProperties += new
PropertyPanel.EventHandler(this.Test);

Of course, this isn't the best way to go about this. Because
EventHandler is already defined, I would just remove the delegate
declaration (but keep the event declaration). Then, your code should be
fine.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"pkiddie" <pk*****@hotmail.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
Hi!

Im having real issues understanding delegates/events in .NET v1, and was
hoping someone could shed some light on where I'm not quite understanding.
I've got this piece of code in a base user control, which i've called
'PropertyPanel'. In it is the following code:

public delegate void EventHandler(object sender, EventArgs e);

public event EventHandler AppliedProperties;

private void buttonOK_Click(object sender, System.EventArgs e)

{

EventHandler handler = AppliedProperties;

EventArgs ex = new EventArgs();

if (ValidateForm())

{

if (handler!=null)

{

handler(this, ex);

}

}

}

Now what I'd like to do is to derive from my base user control several
other property panels, but still hook to my AppliedProperties event
handler within the main form, which will fire from a specific
implementation within the derived class, for example by:

(in the main form)

PropertyPanel myPropertyPanel;

myPropertyPanel = new NodePropertyPane();

myPropertyPanel.AppliedProperties += new EventHandler(this.Test);

OR myPropertyPanel = new LinkPropertyPane();

myPropertyPanel.AppliedProperties += ....

Does anyone know or can give me advice how to best go about this?

Any help would be greatly appreciated,

Paul


Jul 27 '06 #2

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

Similar topics

13
2561
by: z. f. | last post by:
Hi, i have a class that is derived from System.Web.UI.Page, and this is the class i use in my application as PageBase. all other page classes are deriverd from my PageBase instead of the...
5
3140
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
0
7124
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
7326
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
7385
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...
0
5629
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
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3195
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...
0
1558
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.