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

inheritance template missing in vb.net 2005 express
jjbunn
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
Change2
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
-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.