How to add reusable codes in Visual Studio Toolbox

This article shows how to use the Visual Studio Toolbox to make reusable code available to any project.

Introduction

What do we do when we want to use a common set of logic code snippets in every page of a project? 
Usually we create a class library, create a .dll file or add a class file, create it and reference it from there. 
Another important and cool way which can be used in Visual Studio is to add or use code snippets 
into Toolbox tabs. Then later just drag and drop the item into your project page.


Lets' Start

In my project, I wanted to use code snippets shown below in multiple pages. This a simple method which returns a string type. 

I don't want to copy and paste or create a separate class file or a .dll file etc.. 

So, how will I use this code snippet on other pages?

public string hello() { return "www.c-sharpcorner.com"; }

It's simple; just select the method then drag and drop into the Toolbox tabs and a new item gets created. 

This item can be renamed, deleted or added with others like it.


1.jpg


This is another cool feature provided in Visual Studio, great!

Note: For every Visual Studio version you need to add this functionality everytime.


Conclusion

Hope this feature helps you in your daily coding ways. Post your comments.
 


Similar Articles