473,326 Members | 2,655 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,326 software developers and data experts.

EventHandler question

Hi,

Why does:

class A
{
public event EventHandler XYZPressed;
}

class B : A
{
void Bla ()
{
this.XYZPressed (this, EventArgs.Empty)
}
}

give this compiler error:

Error 8 The event 'ABC.DEF.XYZPressed' can only appear on the left hand side
of += or -= (except when used from within the type 'ABC.DEF')

Since B *is* an A (inheritence), you should be able to do this. Right?

This is in VS2003 and VS2005.

Thanks,

Hilton
May 26 '07 #1
1 1068
Hilton <no****@nospam.comwrote:
Why does:

class A
{
public event EventHandler XYZPressed;
}

class B : A
{
void Bla ()
{
this.XYZPressed (this, EventArgs.Empty)
}
}

give this compiler error:

Error 8 The event 'ABC.DEF.XYZPressed' can only appear on the left hand side
of += or -= (except when used from within the type 'ABC.DEF')

Since B *is* an A (inheritence), you should be able to do this. Right?
No. Class A is (nearly) equivalent to:

class A
{
private EventHandler XYZPressedHandlers;

public event EventHandler XYZPressed
{
add { XYZPressedHandlers += value; }
remove { XYZPressedHandlers -= value; }
}
}

Note that the delegate field is private, so you don't have access to it
from B.

Does that make more sense now? If not, read
http://pobox.com/~skeet/csharp/events.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 26 '07 #2

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

Similar topics

2
by: Sandor Heese | last post by:
Question, When using BeginInvoke (on a From to marshal to the UI thread) with the EventHandler delegate I see some strange behaviour. The problem is that I call the UpdateTextBox method with a...
3
by: Remco | last post by:
Hello, Serverside I'm generating a html page. There are different controls for which I want to create an eventhandler manually. Like: document.forms.TextBox1.onchange = EventHandler;...
12
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
9
by: Christopher Weaver | last post by:
Can anyone tell me how I could iterate through a collection of controls on a form while assigning their event handlers to another identical collection of controls on the same form. So far,...
13
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that...
2
by: mawi | last post by:
Hi there, When removing page children controls created dynamically not in last-to-first order, the close button of the last control looses its event wiring, even though the handler is rewired...
4
by: Maarten | last post by:
might be a stupid question but can i set an eventhandler for a variable? regards Maarten
7
by: OfurGørn | last post by:
At runtime I generate 8 pictureboxes, when the user click on a picturebox I fire an onclick eventhandler. Because these pictureboxes are generate at runtime I do not have direct access to the their...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.