473,395 Members | 1,437 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,395 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 2041
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.