Form inheritance - how is it achieved?


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Guys,

Thanks for the help - I'm currently working my way through Ivan's feedback. I've extracted the existing template and copy/pasted info from my new form then zipped up the files into a new, uniquely named, zip file and copies it back into: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\VisualBasic.

I didn't know what was meant by Trent's instruction to go the Visual Studio command prompt but Google to the rescue and I followed the Start>Programs>Visual Studio 2005>Visual Studio Tools and found the command prompt in there. I click this and simply ended up in command window in C:\program files\Microsoft Visual Studio 8\VC. Given that my code is VB I changed the directory to: ..\VB and entered devenv.exe /setup. This seemed to run ok but when I started VS again the only templates I have are: Inherited Form and Inherited User Control.

Contary to all instructions I paniced and went back into the ..\VB directory and entered the devenv command again. No errors but still no templates. I then checked the event log which told me the command I needed was devenv/installvstemplates. However doing this in both the VC and VB directories had no effect.

Any clues on how I recover from this self inflicted wound?


Ivan, specifically on what you have done - its seems to be great approach but have you ever tried changing ProFilmeNET_Base.UI.Windows.Forms.PFNStandardForm and seen the changes perculate through on a rebuild of your app?


Cheers, Peter

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Any clues on how I recover from this self inflicted wound?

Hi Peter, have you seen Pertti's post? http://forum.strataframe.net/Topic7973-10-1.aspx


Ivan, specifically on what you have done - its seems to be great approach but have you ever tried changing ProFilmeNET_Base.UI.Windows.Forms.PFNStandardForm and seen the changes perculate through on a rebuild of your app?

Yes, I have. So far, so good. But I'm not talking about visual inheritance, which seems to be a problem in VS.

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
A template is nice, Peter, but to answer the question in your first post, if you want to create a form with some basic code and then inherit that form by other forms, you can do exactly like you wanted within the first post.  Your only snag was that in each of the partial classes (that includes the .designer.vb file which was probably missed), you have to add the same inherits line.  Or, you can leave the inherits line off and only add it to one of the files (which is what .NET does by default by adding the inherits line to only the .designer.vb file).  The main reason you missed it was probably because the way silly VB hides most of the files within your project by default (as if MS thinks a VB programmer would be scared by seeing so many files in his solution explorer or something).  So, you have to go turn on the "Show All Files" button at the top of the Solution Explorer in order to see the .designer.vb file where the other Inherits line is.

So, if anyone answered this question in the tons of posts on this thread, thanks, but I was just skimming the thread and it didn't looked like all of the discussion was around templates.  Templates are great, and we have several for our projects, but all of our forms also inherit from a base form that is specific to the application... so you really need both.

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Also, if you're making a custom template, then it's a lot easier to put the code in your "My Templates" folder than to put it in with all of the installed templates.  Do this:

Put the .zip file for the template in {My Documents}\Visual Studio 2005\Templates\ItemTemplates\Visual Basic.  This folder is much more user friendly than the other one for several reasons:

1)  Your template shows up under it's own grouping called "My Templates" at the bottom of the Add New Item dialog, not mixed in with all of the others.

2)  You don't have to close Visual Studio, call devenv.exe /setup and then reopen visual studio... just re-open the Add New Item dialog and the template will be re-read.

When we do a custom template for use with one of our commercial products, we don't generally put it in the folder with all of the installed templates for those reasons.  It's a whole lot easier to tweak your template if you don't constantly have to close VS to run devenv.exe /setup just to reinstall your template Smile

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
One last thing... there's an Export Template Wizard that can be reached from the File menu... it will get you 90-100% of the way there on creating a custom template.  Just get the form the way you want it then run through the wizard and it will create the .zip file and dump it into your "My Templates" folder.  It's a lot faster than copying an existing template and modifying it... unless you've done it lots of times, even then the wizard is probably still faster Wink

If you can't reach the wizard from the file menu, then you'll have to add the command to your menu by right-clicking somewhere on the toolbars within VS and choose Customize... at the bottom.  The "Export Template..." command is under the File category.  Just drag it out onto the toolbar or menu where you want it.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Greg, your comment about inheritence is very interesting - could it be that inheritenceis simply the best approach anyway. Now that I think aboutdoes creating a new template just give a head start on things but doesn't help with future maintenance, i.e if I use MyTemplate01 as the base for my forms and, in six months time, find that I missed a facility that I need in all forms then I have to go back and recreate all my forms using the an updated version of MyTemplate01.



Alternatively, if all forms inherited from MyForm01 then I simply change MyForm01 and recompile - is this right?




Peter, I'm thinking that using both is the best, as Ben said. I didn't get the template thing until reading this post though. BigGrin



Let me give you a couple of examples of some of the things done in my base form to demonstrate the usefulness of inheritance:



- It can be configured to set the title of the form based on the value of a field in a BO. Currently I'm setting the BO and the field name as properties in the base form, but it recently occurred to me that since my base form inherits from the SF standard form, I could have just used the BO collection...duh. Then I'd only need to set the field name. The base form has code to react to the navigated event and handles setting the title of the form. I.e. if it is an employee form, the title will be '[employee name] - Employee Form' were [employee name] is replaced by the name of the employee.

- I've included a SF Gradient header and a .NET tablelayout control just under it to show the client and project context of the form (most of my forms are within the context of client/project). The base form has a property so the project ID can be set. The base form handles the Load event of the form and sets the header up, looking up the client and project name using the project ID.



In both cases, if I find a bug or want to change the behavior I have one place to fix it. If I find myself copy/pasting the same code between forms, I start thinking about how to use inheritance to reuse the copy/pasted code. As an example, when I first coded the loading of the project/client name, I was looking it up always. Then I realized that in most cases I could cache this info, so I just changed the code to use a cache and a property to force a lookup. About 80% of the forms in my app used this base form and they all got fixed instantly. BigGrin I really like using inheritance because it allows very iterative programming. As I figure out that I have repetitive code in a form, I refactor, pulling out the repetitive code and put it my base form. I'm actually about to refactor my base form into two base forms, one that has very common code (like the title setting bit using a field form a BO) and my project base form (which would have the custom header for projects). Thus I'd have a specific project form inherit from the project base form which inherits from the general base form which inherits from the SF standard form which inherits from the .net form! This can get a bit confusing (because the features implemented in a form are spread all over the place..see note at end), but believe me, the first time you find a bug or want to change/add a feature that is in the general base form and see the change reflected instantly in ALL forms inheriting from it...oh baby w00t



However, to use this base form, I have to manually open the designer file and change the inheritance. This is where the template would be really nice. When I get a moment, I'm going to give it a try!



NOTE:

I've found that using xml comments and keeping them updated is very helpful as those comments get pushed into the object browser. This allows me to more quickly remember how I've done things. I can see the inheritance, which property/methods are in which of the inheritated forms etc.



Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Gentlemen,

Thanks for the great feedback guys - this is really got me rolling,

Ivan thanks for the link - I hadn't seen it however, guess what, this morning all my templates are back. I have no idea how that happened. I 'nearly' certain that I tried a VS restart when trying to fix the problem before but maybe I didn't.

I also followed Ben's advice re the location of the template file and that's much better.

About to start trying to bring this all together. If I find any interesting info that will be useful, as part of this thread, I add it in.

Cheers, Peter

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey Peter.

Glad to hear that.

Wink

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search