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:
Item Templates are templates you select when you're adding a new item to your project:
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...
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.
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.
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.
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).
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".
That was everything about templates I'll teach you in this tutorial, I hope you learned something new and have a good time![]()
Nice work! +rep![]()
Nice +rep
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks