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

Same Abstract Class for Different Controls

I have an abstract class which uses System.Windows.Forms.UserControl as it's
base class. It has some custom drawing methods and it also handles a few
common events like Paint, PaintBackGround, etc.

When I create a new UserControl I specify my abstract class as its base
class and it works beautifully. However, I would also like to create a new
Form and specify my abstract class as its base class so I can use the same
custom drawing methods and have it automatically handle the Paint events for
the form as well. The problem is I can't because the abstract class uses
UserControl as its base class and not Form.

I believe in C++ I would have used multiple inheritance (both the form class
and my abstract class), however, in C# that's not possible.

My first thought was to use an interface but from what I understand
interface members can not have defintions so I would have to recode the
custom drawing methods in each control that used the interface (messy).

What is the best way to do this?
Nov 16 '05 #1
3 2032
I would suggest having 2 base classes. Each base class handles the event,
but all it does, is calls a function defined in another class, passing it
some arguments if necessary.

The idea is, that the function that actually does the work would be coded
once, and each of your base classes would only just call the functions in
your 'worker' class to do work for them.

"Jeff" <a@a.com> wrote in message
news:OQ****************@TK2MSFTNGP12.phx.gbl...
I have an abstract class which uses System.Windows.Forms.UserControl as it's base class. It has some custom drawing methods and it also handles a few
common events like Paint, PaintBackGround, etc.

When I create a new UserControl I specify my abstract class as its base
class and it works beautifully. However, I would also like to create a new Form and specify my abstract class as its base class so I can use the same
custom drawing methods and have it automatically handle the Paint events for the form as well. The problem is I can't because the abstract class uses
UserControl as its base class and not Form.

I believe in C++ I would have used multiple inheritance (both the form class and my abstract class), however, in C# that's not possible.

My first thought was to use an interface but from what I understand
interface members can not have defintions so I would have to recode the
custom drawing methods in each control that used the interface (messy).

What is the best way to do this?

Nov 16 '05 #2
Hi Jeff,

I think Marina's suggestion may meet your need. Have you tried his
suggestion? Do you still have any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #3
Hi Jeff,

I think Marina's suggestion may meet your need. Have you tried his
suggestion? Do you still have any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #4

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

Similar topics

12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
2
by: Joe Vrba | last post by:
I'm building a family of components derived from UserControl. There's an abstract base class to ensure basic functionality and then numerous other controls derived from that. The problem is...
1
by: Jeff | last post by:
I have an abstract class which uses System.Windows.Forms.UserControl as it's base class. It has some custom drawing methods and it also handles a few common events like Paint, PaintBackGround,...
4
by: Chuck Bowling | last post by:
I am using CodeDOM to generate source files. The classes being generated have a const string member. This member is referenced in an abstract base class but declared in the inheriting class. I...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
6
by: steve bull | last post by:
I created a usercontrol class, RGBColorSpace, which is derived from an abstract class, ColorSpace, but when I try to click on the design panel for the control I get an error message "Unable to...
6
by: Steve | last post by:
I am designing a new class hierarchy and I've already run into a bit of a bump in the road. I have this structure so far; class CodeGen class CodeGenHeader : CodeGen class CodeGenProtocolHeader...
8
by: diatom | last post by:
Is it possible to create a windows form as an abstract class? Let me explain ... I am writing a windows applciation where I will need around 100 dialogs - each with a similar look, feel, and...
2
by: emaileric | last post by:
Hi all, I am looking for a way to create two different forms, with different look and feel. However, they would both have the same set of controls, and reference the same code behind page. I...
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...
1
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: 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: 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.