Same Abstract Class for Different Controls

J

Jeff

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?
 
M

Marina

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.
 
J

Jeffrey Tan[MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top