Click here to Skip to main content
Click here to Skip to main content

Create Visual Studio forms for items you frequently use

By , 8 Jan 2012
 
I don't know why I never thought of it before, but it is really easy to do.
 
Step 1: Create your blank
Create a new Windows Form by right clicking your project and selecting "Add...Windows Form".
You can leave the name at the default value, as you will delete it at the end of the process, and the name is irrelevant to the template.
Add two buttons, one of the left of the screen, and then one on the right. (If you add these in the wrong order you will need to change the tab order or the user could get confused).
Move the right hand one into the bottom right hand corner of the form (so that the blue lines appear to the right and bottom of the button).
Change its name to "butCancel" (or whatever your normal name would be).
Change the Text property to "Cancel"
Change the DialogResult property to "Cancel"
 
Move the left hand button into position to the left of the Cancel button - again, the lines will tell you when it is correct.
Change it's name to "butOK" (or whatever your normal name would be).
Change the Text property to "OK"
Change the DialogResult property to "OK"
 
Highlight both buttons, by clicking on one, then holding down CTRL and clicking on the other.
Change the Anchor property from "Top" and "Left" to "Bottom" and "Right".
 
Highlight the form.
Change the Text property to "OK Cancel" or similar.
Change the AcceptButton property to "butOK".
Change the CancelButton property to "butCancel".
Change the MinimumSize property to "196, 0".
 
Step 2: Save as a template.
On the File menu, select "Export Template..."
In the resulting dialog box, select the "Item template" radio button - the default is "Project template" which exports a whole lot more than you want!
Select the appropriate project (the one you added the blank OKCancel form to), and press "Next >".
Select the blank OKCancel form, and press "Next >"
Do not add any references, unless you need them in all your forms - Press "Next >".
Give the template a sensible name and description, and press "Finish".
 
Done! You can now add a blank OK/Cancel form to any future projects.
You can delete that blank from your project now.
 
Using this I have added two "blank" forms - OKCancel and InputBox, simply because I generate forms based on these far too often!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

OriginalGriff
CEO
Wales Wales
Member
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 3 Use one of VS templates - Dialog win...memberVinden14 Jan '12 - 9:52 
GeneralReason for my vote of 5 Nice reminder of VS.Net's features.memberVBGuruWantabe11 Jan '12 - 6:57 
GeneralReason for my vote of 4 Concise, clear instructions for a ve...memberwkiess0110 Jan '12 - 11:09 
GeneralReason for my vote of 5 Quite helpful. How about changing th...memberus47119 Jan '12 - 12:03 
GeneralReason for my vote of 5 nice postmemberhtxuankhoa8 Jan '12 - 2:34 
QuestionGreat PostmemberEric Castellon8 Jan '12 - 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 8 Jan 2012
Article Copyright 2012 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid