473,322 Members | 1,911 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,322 software developers and data experts.

Handling event methods from inherited classes.

Hi all i have a c# problem,
i have a base class Page and a good few classes inheriting from it.
the events and delegates are declared in the base class page but
different classes have different methods for the same event,

ie page_leave event would be different on the homepage than on an
artistpage.

how or where would i assignt the event methods?? any help appreciated.

bryan

Mar 24 '06 #1
7 1463
You could add the event handlers in the Page_Load method or the
InitializeComponets method.

Mar 24 '06 #2
Thanks for the quick reply.

this is just a cs class no page_load or InitializeComponets. the Page
class is called from a form with an InitializeComponets but the events
are not accessable from there.
at the moment the base class Page has an Virtual method called
DisplayPage. This is overridden in every inherited class and at the
moment this is where i am assiging the Events to the methods but this
is causing loops and unpredictable behaviour.

regards
bryan

Mar 24 '06 #3
Constructor then?

Mar 24 '06 #4
Maybe i should try and clarify with code.

public abstract class Page : IDisposable
{
public virtual void DisplayPage(ref frmMain myForm)
{
this.albumList.LeaveControl += new
dmControls.imageList.LeaveControlEventHandler(albu mList_LeaveControl);
.............
}
public delegate void
AlbumListLeaveControlEventHandler(dmControls.Direc tion direction);
public event AlbumListLeaveControlEventHandler
AlbumListLeaveControlEvent;

private void albumList_LeaveControl(dmControls.Direction direction)
{
if (AlbumListLeaveControlEvent != null)
AlbumListLeaveControlEvent(direction);
}
}

public class AlbumListPage : Page
{
public override void DisplayPage(ref frmMain myForm)
{
AlbumListLeaveControlEvent += new
AlbumListLeaveControlEventHandler(AlbumListPage_Al bumListLeaveControl);
.......
}
private void
AlbumListPage_AlbumListLeaveControl(dmControls.Dir ection direction)
{
if (direction == dmControls.Direction.Left)
{
this.theForm.GoBack();
}
}

Mar 24 '06 #5
yes but is the base constructor called last? would this not override
any assigments made previously while creating the inherited class?
when i debug this seems to be the case

Mar 24 '06 #6
bump

Mar 25 '06 #7
You have to manualy call the base constructor from the derived class.

You do this like this:

public MyConstructor ( parameters ) : base ( parameters )
{
....
}

Mar 25 '06 #8

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

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
2
by: Mark | last post by:
I have it in my head that I saw a marketing document from Microsoft with the total number of classes and methods in the .NET Framework. Something like 70,000 methods? I don't need precise numbers,...
3
by: Edward Diener | last post by:
According to the CLS specification, the accessibility of the methods for adding, removing, and raising an event must be identical. There appear to be a few problems with this: 1) According to...
6
by: **Developer** | last post by:
usually I'd do: Drawing.Image.FromFile( I noticed I once did without thinking: Drawing.Bitmap.FromFile( I assumed this worked because Bitmap inherits from Image, but for fun I thought I'd...
3
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. ...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
4
by: Mythran | last post by:
I once read an article somewhere describing why we should not override the OnXXX methods of classes when you want to extend the functionality of a class. It stated that you should handle the event...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
5
by: Rafe | last post by:
Hi, I've been thinking in circles about these aspects of Pythonic design and I'm curious what everyone else is doing and thinks. There are 3 issues here: 1) 'Declaring' attributes - I...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.