Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Got sweet code? Save it!

, 12 May 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
If you’re a Visual Studio user you’re more than familiar with snippets (I would hope). ctor, propa, testm, all very useful. But have you created your own snippets? You can do this with tools like the Snippet Designer extension, or roll your own by creating & editing a snippet XML file by hand based

If you’re a Visual Studio user you’re more than familiar with snippets (I would hope). ctor, propa, testm, all very useful. But have you created your own snippets?

You can do this with tools like the Snippet Designer extension, or roll your own by creating & editing a snippet XML file by hand based on the snippet schema.

Ain’t nobody got time for that.

Far and away the quickest way I’ve found to save code I reuse often is even simpler than all that. And I’m about to clue you in on it.

If you’ve been to BUILD or other conferences/presentations by Microsoft folk, you’ve undoubtedly seen them take their “sample code” and insert it via a snippet. But what I saw at BUILD 2014 this past April surprised me. All the presenters had the toolbox open *in code view* and were simply dragging & dropping code snippets from the toolbox right in to their code window. Every time they did it, they did so fast that I wasn’t even able to see exactly where things were coming from or what they looked like.

This past week I was preparing for a presentation and decide to just give something a whirl:

I got my code all ready in my sample app, and highlighted it. Then I got an idea… what if…

Sure enough, just dragging the code over to the toolbox gives you a little ‘text’ entry in your toolbox. You can even rename it so you know what you’re going to use it for:

Now, when you want to use it again, you just drag that toolbox item back in to your code:

And boom, it appears.

Insanely useful for doing live-code presentations, or storing away snippets you use over and over without the hassle of actually writing a snippet.

The best part? These items persist across VS launches; they’ll be there the next time you launch Visual Studio

License

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

Share

About the Author

BC3Tech
Software Developer (Senior)
United States United States
No Biography provided
Follow on   Twitter   Google+

Comments and Discussions

 
SuggestionShare its tools within a developer team [modified] PinmemberPascal-7812-May-14 21:26 
QuestionImages not showing! PinmemberCarlos190712-May-14 1:44 
AnswerRe: Images not showing! PinmemberBC3Tech12-May-14 10:49 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 12 May 2014
Article Copyright 2014 by BC3Tech
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid