• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 950
  • Last Modified:

Abstract UserControl problem

I am using C# 2.0 VS 2005. Windows Forms.

I have a base UserControl that I have made abstract, as I want to force concrete UserControls that inherit from this BaseUserControl to implement certain abstract methods.

My problem lies in the fact that I can't enter the designer and see the design time view of the UserControls. When Visual Studio attempts to render the UserControl it must automatically attempt to instantiate the base class so I get an error like:

The designer must create an instance of type 'Tools.ToolBase' but it cannot because the type is declared as abstract


How to get around this, or suggestions for this scenario?

Thanks
0
craigdev
Asked:
craigdev
1 Solution
 
craigdevAuthor Commented:
no body has any answers on this?
0
 
ripahoratiuCommented:
Well, it might be one or two but they are workarounds:
1. Instead of having your methods/UC abstract place some virtual methods there.
or
2. Isolate into an Interface the abstract methods. Make your control to derive both
or better
3. Use an inner Interface in base, to still make use of the abstract functions calls, i.e.:

public partial class UserControl1 : UserControl
    {
        public interface IAbstractFunctions
        {
            void MyFunction(string something); // abstract
        }
        ....
        public void SometingCallingTheImplementedFunction(IAbstractFunctions objFunctions, string strParameter)
        {
            objFunctions.MyFunction(strParameter);  
        }
   }


and

  public partial class UserControl2 : UserControl1, UserControl1.IAbstractFunctions
    {
        ...
        private void UserControl2_Load(object sender, EventArgs e)
        {
            base.SometingCallingTheImplementedFunction(this, "that's me The derrived one, calling the implemented MyFunction");    
        }

        public void MyFunction(string something) //implementation of the abstract function
        {
            MessageBox.Show(something);
        }
    }



0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now