Drag and Drop Code Into Toolbox in Visual Studio

If you have some code that you use often then it's time to start using the Visual Studio Toolbox since it's for more than just controls. While working with the Visual Studio code editor, it appears as in the following:

Image 1

Just to demonstrate, I use these two lines very often while coding:

Console.WriteLine("Action Completed. Press any key to continue...");

What I'll do is, I'll just select the code that I want to be ready on the move and just drag it into the Toolbox in the left pane of the editor. It will be added and shown in the Toolbox like this:

Image 2

You will see what this code snippet contains by hovering over it.

Image 3

And this is not limited only to two lines of code, it could be any count. You have the code ready to go anytime. Just place the cursor where you want the code and double-click the item/snippet in your Toolbox. You have the choice to drag & drop it also for the same.

The Toolbox offers you the opportunity to rename this snippet also with a friendly name by right-clicking on it.

This technique can help you code faster and make you more productive.

Hope you enjoyed reading this article.

Feedback and comments are highly appreciated. Follow for more!

Up Next
    Ebook Download
    View all
    View all