inheritance template missing in vb.net 2005 express

I'm trying to experiment with form inheritance and created a base form with a couple of buttons.  I save and build this base form as a dll.  Then I try to add another form which inherits the base form, but the project menu has no items to allow me to add an inherited form.  I've also tried adding a reference to the project first, but it still doesn't work.  What is wrong

Answer this question

inheritance template missing in vb.net 2005 express

  • jjbunn

    Not one to give up easily, I decided to see whether it would be any different if I just created a project with a base form in it, build it as an executable, then create a new project within the same solution and try to inherit the base form...NO GO.  I still get an error saying the base class cannot be different from the base class "System.Windows.Forms.Form"...even though I explicitly put an "inherits System.Windows.Forms.Form" statement right after its class statement.  I can't find the working combination with express 2005.
  • Mr Brown Shoes

    John,

    As an immediate solution I would suggest you use inheritence directly.

    Add a new class.
    As the first line of the new class definition type

    Inherits [Namespace][.Additional Namespaces].[Base Form Class] such that your class definition would read:

    Partial Class MyDerivedForm
       Inherits WindowsClassLibrary1.MyBaseForm
       ...
    End Class

    Save and from that point forward the solution explorer should treat the form like any other Form. I'm not sure the partial class Just My Code feature will work automatically but make the class partial just to be safe.

    Hope that helps.



  • HMCSharon

    PS, any member of your base form that you want to be accessible outside of your DLL must be declared Public, Protected, or Protected Friend.

    By default form members are declared Friend. Making them protected or protected friend will make them accessible and editable by subclassed forms.

    You can also experiement with Visual Inheritence without compiling to a dll at all. If you want a more direct and managable experiment, create your base form and then follow the procedure outlined above - you can always Inherit from Forms and other classes that are in the same project that aren't expressly defined as NotInheritable.



  • Thomas Ott

    Well, thanks to both of you for your replies.  Regarding the "add a class" approach, I believe that's the way I eventually got around it before.  Rather than try to add a form to the project, I simply added a class that inherited the base form.

    Inheritance template, that would be useful.  You could email it to me at:

    joblacker@mindspring.com

    Thanks.


  • Bene

    "This is the end...."  I tried using the Express version of C# to see what would happen.  It too is missing the "automatic" inheritance capability; but I was able to create a base class in one solution, then add a "using MyBaseFormClass;" in the derived form code, and append "    : baseForm" to the class definition of the derived class and all works.  The derived class inherits the base classes two buttons (and they're functional) and it has it's own button as well.  There must be a moral to this story, but I don't know what it is.  Maybe something like: "VB just isn't quite there yet as a truly object oriented language"    Or, maybe it's "Back to Java!" where I didn't have all these hassles, ever!
  • Change2

    John mumbled "Maybe something like: "VB just isn't quite there yet as a truly object oriented language"    Or, maybe it's "Back to Java!" where I didn't have all these hassles, ever!"

    Or maybe it's the express IDE. This isn't the only sad VB story to be told, the only upside is that you don't have to pay for it to annoy you. Now if you want to talk 2002 & 2003, well some people paid to have it annoy them. Anyway you have my permission to run back to Java or C#. Here's an old addage "Go with what you know." Or you could stick around, meddle in things, etc.

    You guys made this sound so very difficult.

    Here are three very easy steps.
    1. Compile your DLL containing your form class.
    2. Reference your DLL in the project you want to inherit your form.
    3. Start a class file (not a form file) and add inherits ClassLibrary.MyBaseForm

    The Designer will even then recognize it as a form and display it for you. If you want free VB then you have to accept the IDE's limitations. Just remember that all of Dot Net is still available to you as the programmer, regardless. You want to hear how 2002 & 2003 didn't have a Class Library template and it was not allowed to compile DLLs from the IDE Probably not. Here's another one for you "Where there's a will, there's a way."

    Next you'll be wanting to write a windows service.....

    Thanks Anthony for reminding us  "
    PS, any member of your base form that you want to be accessible outside of your DLL must be declared Public, Protected, or Protected Friend."

    Randy

  • evilone

    Actually, rather than add a class I simply added a windows form and changed the boiler plate code "inherits" statement and everything worked.  I've been working with VB.NET 2003 and wasn't cognizant of the separate code file (duh!) wherein the boiler plate code is housed.  Clicking "show all files" in the solution explorer and then modifying the boiler plate inherits statement was all that was necessary. 

    Ok, maybe it's a bit premature to switch back to that other product...


  • Allan E

    "Inherited form" is not on the list, that's the reason for my original post.  Here is a list of what I have available:

    Windows form, dialog, explorer form, mdi parent, about box, login, splash, class, module, dataset, sqldataset, user, text.  Nothing titled "Inherited Form!"


  • Arjan Mels

    Click the "Add new item" and you'll get a list of templates. One of which is "Inherited Form"
    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • Gerald00

    Well, got curious and went back and tried Mr. Greens approach.  I recreated the base class as a dll with two buttons, each declared as Protected Friend.  Then built that solution.  Next I created a new project, added a reference to the base class dll, then changed the new form to be "Partial Class form1" and added a new statement: "Inherits My_Base_Form_2005.Base_Form" and got the following error:

    Error 1 Base class 'My_Base_Form_2005.Base_Form' specified for class 'Form1' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types. C:\Documents and Settings\John\My Documents\Visual Studio 2005\Projects\My Inherited Form 2005\My Inherited Form 2005\Form1.vb 2 14 My Inherited Form 2005

    It doesn't seem to matter whether the new form is declared Public or Partial...same error!  Ideas


  • Tarek Haoula

    ICQ#: 11498407
    MSN: ad_green@lycos.com
    AIM: faroreofdejoa

    You should drop me a line on an instant messenger if you have problems/questions.

    In answer to your last post, it's not a problem with VB itself. No offense intended but it's probably a problem with your code, possibly related to the partial classes and designer code separation and what not. I'd be glad to look at it for you, no reason you should have to switch languages for something simple. Beyond that Express probably has a way to import project templates, I can give you my Inherited Form template from VS2005 Standard.

    From the sound of it the compiler is detecting some conflict in your source.



  • hidayet

    Well, several things are coming to light.  First, it's obvious to me that M/S has removed the "automatic" forms inheritance capability from the "express" version.  A quick browse of the various directories/sub-directories indicates that there is no Inheritance.Zip file which would be the basis for the "automatic" inheritance capability.

    As Mr. Green suggested, I also tried using the brute force approach, but I didn't declare the inherited form as a "partial class" and I didn't use the "WindowsClassLibrary1.MyBaseForm" But I used something like: "inherits MyBaseForm.frmBase" instead.  When I tried to run the app, I got an error, something to the effect that the inherited form couldn't inherit something that wasn't a derivative of System.Windows.Forms.Form.  Anyway, it's been a few days since I began this quest and can't exactly remember what I had to do, but I know that after going through some gyrations, I was able to get something to work. 

    I guess M/S is intending the "express" version for more mundane experimentation with the intent to whet folks apetite so they'll purchase a full version...I suspected the old adage about "you get what you pay for" is true in this case.  I would suggest a better way would have been to limit the product in some other way without crippling the functionality which is one of the major "selling" points of the "new .NET" version!


  • Olivier Dagenais

    I've moved this thread over to the VB forum. Maybe they removed the template for the Express edition, or maybe it is a setup problem.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

     

    -mark

    Program Manager

    Microsoft

    This post is provided “as-is”

     


  • Hiryux

    Ah HA, I reread your post and now I understand

    I mentioned adding a new class to your project to avoid this project.

    When you add a form to the project, at least in VB it puts all the boilerplate code in a separate file and uses Partial Classes to combine them at run time. Included in that Form.Designer.vb is an Inherits clause. Your error is originating from you having a different Inherits clause in your user code file. The default Designer file specifies System.Windows.Forms.Form as a base class and your Partial form specifies the Base form so the compiler fails to reconcile. Drop me a line sometime and I'll try to walk you through it, if you need it.



  • inheritance template missing in vb.net 2005 express