Visual Studio 2013: Drag and Drop Code Onto the Toolbox

This is another feature that has been around for a while but a lot of people don’t know about. Got code you use all the time?  Start using the Toolbox for more than just controls.  When you are in the Editor the Toolbox looks like this:

5-16-2012 12-09-16 PM


This is a vast expanse of opportunity!  Just select some code you use often and drag it into the Toolbox and see the magic happen:

5-16-2012 12-11-35 PM


Now you have code ready to go at anytime!  Just place the cursor where you want the code to go:

5-16-2012 12-13-32 PM


And double click on the item in your Toolbox to have the code inserted:

5-16-2012 12-14-46 PM


You can also Click and Drag where you want the code to go:

5-16-2012 12-15-49 PM




Additional Actions

There are a few extra things you can do with this feature as well. Here is are a few things to consider.



You can rename the code copy to whatever you would like by RIGHT CLICKING on the item and choosing Rename Item:
5-16-2012 12-17-53 PM



Additional Tabs

You can also create additional tabs beyond the General tab. To organize the code with additional tabs just RIGHT CLICK any open space in the toolbox and choose Add Tab:
5-16-2012 12-20-58 PM


This will produce a text box where you can type in the name of the new tab:

5-16-2012 12-22-29 PM


Simply enter a name and press ENTER:

5-16-2012 12-25-15 PM


And now you can click and drag code into the new area:

5-16-2012 12-26-40 PM



Showing the Code

You can see the entirety of any code entry by placing your mouse cursor over the item and reading the tooltip:

5-16-2012 12-27-55 PM




You can delete any entry or any tab except the General Tab. Simply RIGHT CLICK the item or tab and choose Delete or Delete Tab respectively:

5-16-2012 12-30-45 PM

Comments (10)

  1. Thank you. That is an extremely sweet function indeed.

  2. teoman says:

    nice, does it work also with VS 2010?

  3. zainnab says:

    Yep. It's been around for a while.


  4. raffythegreat says:

    Can I export this to other PCs I use other than the one I created it from?

  5. zainnab says:

    Hey Raffy 🙂

    Currently you can't export and import these items. I'm not sure if that will change now that we have roaming profiles with VS.


  6. Yann Duran says:

    I got really excited about this a while back, but the lack of the ability to actually edit the code fragment once it's been added to the tool box (in case of a revision to the code) made it very tedious to use, so I gave up. I was hoping that by now, editing would have been possible, but sadly no.

  7. This is a great feature - but sadly without import/export it lacks says:

    Without the ability to import and export these the feature is not valuable.   When I upgrade my PC I lose all of this.  When I upgrade from VS2010 to VS2013 I lose of of it… That's just moronic.

  8. Prithvi says:

    how can i bring tools like button ,checkbox and all other stuff into the toolbox

  9. Steve D. says:

    I learned about this feature when watching a training video on an unrelated topic.  I really like it and use it a lot.

    There is one annoyance:  When I drag the code into a source file it adds the wrong line endings.  It really should keep the line endings of the original source.

    The text looks and saves fine, but the next time I load the file I get a warning about wrong line endings.  I fix the line endings and everything is fine.  When I forget to close and re-open a file to fix the line endings before checking in to version control (for example: when I add a boiler-plate copyright header to a file), I later check in the fixed version and have two versions in source control that differ only in line endings (icky).


  10. Sean M says:

    Yup this unfortunately doesn't keep line endings (Vs2015 CE). Ended up installing Snip 'em to do this. Also it seems to not always keep indentation. I tried adding hex characters and such into the XML file you can get from export, but it just messes it up worse. Would be great if this worked more like snippets.

Skip to main content