+ Reply to Thread
Results 1 to 3 of 3

Thread: Create your own template - VB.NET

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Create your own template - VB.NET

    In this tutorial I will show you how to create and use your own templates. There's two types of templates; project templates and Item templates.


    Project Templates are templates you select when you're creating a project, it could contain more then one Item:

    Create your own template - VB.NET-template1.png




    Item Templates are templates you select when you're adding a new item to your project:

    Create your own template - VB.NET-template2.png


    In this tutorial I will focus on creating an item template since when creating them you need to choose a few more things. Now its time to create the item we want to create a template from. Since this is not so important in this tutorial since I'm just showing how to do it I won't use a so complex template or so very useful either. So if you have your own item that you just want to learn how to save you don't need to create this example item.


    First I'll create a normal form and change these properties on it:

    ControlBox to False
    FormBorderStyle to FixedToolWindow



    Then we can also add objects to the item which then will be saved into the template, so I'll add a Label and change the font size to 18 and add the text "Click on the form to Exit".


    At last we will also add some code to our template, we'll add what we told was possible (i.e. Exiting by clicking on the form). By adding this code:

    [highlight=VB.NET]
    Private Sub myTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
    Me.Close()
    End Sub
    [/highlight]

    So now we have a form with some changed properties, a label and some code which will close it if we clicks on the form(observe that this is only an example which also is the reason this template will be so simple) so if don't want to redo "all" this work(it could be a lot if the form is complex and actually useful ) we can save this item as it is as a template which will result in that we'll get a form with these properties, the label and our code each time we create a new instance of this template. So now we want to export this to a template.

    To do this, begin with clicking File and then Export Template...

    Create your own template - VB.NET-template3.png


    Now you'll see the window on the image below, select which type of template you want to create (Project Template or Item Template), then if you have more projects in your solution you'll have to select which/from which - project you want to create the template from and lastly click next. Since we want to export our form to a Item Template, select that option.


    Create your own template - VB.NET-template4.png




    Now if we selected Item Template we'll need to select which item we want to create a template from, so just select the correct form and the click next. Even though it looks like checkboxes you can only select one, this will be a Item Template after all.


    Create your own template - VB.NET-template5.png



    Now we'll need to select which references we want to include in the template, in the list we can found all references that is added in the reference list of the project(can be found by double-clicking on "my project" in the solution window and then going to "References") I've already removed the references that I don't need in my project so it's just to select them all. Where you found all references for your project you can see which references that isn't used so you know which you don't have to include in your template(but as I said for me it will be all since I've removed the others from my project's reference list so they won't be in this list either), then click Next.



    Create your own template - VB.NET-template7.png





    Now we'll come to the last window. If we had created a Project Template we would have got here right away since we wouldn't have to select which item or which references to use(since it uses the project's references). Here we can choose: The icon for the template(or you can use the default), the name and its description. You can also choose if you want to change the output location, if you want to auto import the template to visual studio(so you'll be able to use it) and if you want to open a file browser showing your template. Then click finish to create the template, the template will now be saved(templates are saved as .zip files).

    Create your own template - VB.NET-template8.png




    You'll now found your template in the list of templates. The first time you tries to add it, it asks if you trust the template our not. But since you probably trust yourself you can just click "Trust".


    Create your own template - VB.NET-template9.png



    That was everything about templates I'll teach you in this tutorial, I hope you learned something new and have a good time

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Create your own template - VB.NET

    Nice work! +rep

  4. #3
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Create your own template - VB.NET

    Nice +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. php in template?
    By Hamed in forum PHP Development
    Replies: 2
    Last Post: 12-10-2010, 08:18 PM
  2. Replies: 0
    Last Post: 07-23-2010, 03:41 AM
  3. Div-CSS Template - Help?
    By Momotaro in forum JavaScript and CSS
    Replies: 2
    Last Post: 06-25-2009, 06:18 PM
  4. New template
    By Jaan in forum Website Design
    Replies: 20
    Last Post: 10-30-2008, 11:44 AM
  5. How to Create a Template
    By Xav in forum Website Design
    Replies: 16
    Last Post: 10-23-2008, 09:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts