Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS VB 2005 Express Edition - inheritance template? 1

Status
Not open for further replies.

surfside1

Programmer
Feb 12, 2006
209
US
Does anyone know if you get the inheritance template with the VB 2005 Express Edition? I have the MS VB 2005 Step by Step book and in chapter 16 it says to use that template but I don't see it as an available template.

Also I'm wondering if using the Express Edition is the way to go and what it does not offer that I could get in another version of VB.NET.

Thanks!
 
There's a template for inheritance?

Code:
Public Class MyBaseClass
  Sub Overrideable MyMethod()
    msgbox("MyBaseClass.MyMethod")
  end sub
end class

Public Class MyChildClass
 Inherits MyBaseClass
  Sub Overrides MyMethod()
    msgbox("MyChildClass.MyMethod")
  end sub
end class

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Well, it says to select "Build My Form Inheritance" command on the "Build" menu and that VB compiles an .exe file. Then to Click the "Add New Item" command on the Project menu and click the Inherited Form template, but I don't have one. It is supposed to display the Inheritance Picker and then you select the form you want to inherit.
Ever done that?
Thanks!
 
Never through the GUI. Just make another class and right under the class name add the line "Inherits ClassName" where ClassName is the name of the class that you want to inherit from.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks, I'll give it a shot tomorrow. I'm totally new with VB.NET and have not made classes before. So I'll study your code and may be back if you don't mind.
Thanks, again
 
Thanks for your code sample but I'm confused, I guess because I'm not sure of when the classes are used. What I want to do is build a template form that has the background image, copyright, logo, menu, etc. Then when new forms are added to the project they will pick up the format before any changes are made for that particular form and when the template changes all forms change automatically as well as new forms. How do I start? I have a form to be inherited. Thanks!
 
First, make your "template" form.

Next, add a 'new item' to the project. When the "Add New Item" dialog comes up, look for "Inherited Form".

Click OK.

A new dialog "Inheritance Picker" should appear. Select your template form and click OK.

You should now have a new form that looks just like your old form.

Unfortunately, controls are declared 'friend' by default, so you wont be able to move anything. This may not be an issue if you can configure everything on the template for with anchors. But, if you need to have more control...

In the solution browser click the "Show All Files" button.

Browse to your template form and click the "+".

select the form.Designer.vb file and switch to code view.

Look for a block of declarations like:
Code:
Friend WithEvents Label6 As System.Windows.Forms.Label

Friend allows access to the controls from the assmebly, but it doesn't give the inheriting class full control over them. So you want to add the word 'Protected' to the front of the declarations. Protected means that any class that inherits this class will have full control over that object. So it should look like this:
Code:
Protected Friend WithEvents Label6 As System.Windows.Forms.Label

You'll have to do that for any controls that you want to be able to move.

Rebuild the project (Ctrl-F5).

Now when you go back to your form that looks like the template, you should be able to move controls around.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
OK this gets me back to my response to your first response "There's a template for inheritance?"

I don't have one there for some reason. I'm wondering if there is one I can download or something? Thanks!
 
No idea, but you can still do it the manual way.



In the solution browser click the "Show All Files" button.

Browse to your template form and click the "+".

select the form.Designer.vb file and switch to code view.

At the very top of the code you should see:
Code:
Partial Class frmMain
  Inherits System.Windows.Forms.Form

Change this to:
Code:
Partial Class frmMain
  Inherits MyTemplateClass
but use the name of your template form in place of the "MyTemplateClass".


That's all the inherits from picker does.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Great, works like a charm.! Thanks for taking the time to document. Surfside1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top