Search code examples
winformsvisual-studio-2008c++-climanaged-c++

Are Inherited Forms And/Or Inherited Controls possible in Managed C++


The question is actually pretty self explanatory but I will further clarify it. I am building a simple application to show a load [file] for 5 different types of [files]. So all these 5 forms will have similar GUI elements such as a listbox and a load button with a small textbox/label to show the summary of the [file]'s information.

My desired effect is something like visual studio's C# template for Inherited User controls or Inherited forms. I already heavily googled the concept to look for a C++ visual studio template to the trick but I couldn't find it.

The word [file] is in brackets because open file dialogue will not the trick as this list of files to select form comes form an SQL server.

Thanks a lot!

To further explain my desire:

Class A : public System::Windows::Forms::Form
{
  //normal windows forms generated code here and your stuff
}
Class B : public A
{
  //You cannot edit this content with designer as designer denies you that chance
}

So I wonder If I can use the designer to edit this class too. I tought if I can make designer not read the class declaration instead see something like this

#if designer
Class B : public System::Windows::Forms::Form
#else
Class B : public A
#endif
{

}

I am looking for something to do this where I can both use the designer on the Inherited form and the Base form. Is it even possible.


Solution

  • Yes, no problem. C++/CLI supports inheritance just as well as any other managed language. What is missing is the point-and-click IDE support, you'll have to type. Add the base form to your project, change the derived Form declaration. For example:

    #pragma once
    #include "BaseForm.h"
    ...
    public ref class Form1 : public BaseForm         // <== NOTE: new base class
    {
      // etc...
    }