In the previous article, we discussed about VS add-ins. In this article, we will look into interfacing Win Forms with it. Integrating Win Forms in add-ins gives a better UI for interactions. I am going to explain the integration with a sample. Open our VS 2008 and create a new VS add-in as explained in the previous article with the name WinFormAddin.
Now add a new Form named MyForm to the add-in as shown below.
![WinFormAddin]()
We will make our Form to show a list of opened VS windows. Design the form as shown below.
![Windows]()
Go to connect. cs and add the below code to the Exec method.
Here, we are passing DTE2 to our form. By using this DTE2 instance, we can work on Visual Studio IDE events, windows, etc. When we run our add-in, it will call Exec(). In this method, we are defining the form's instance and passing DTE2 (_applicationobject) to it.
Now, go to code-behind behind MyForm and add the below code to it.
On Form load, we are getting a list of opened windows using MyDTE.Windows collection. Then, we create a button and contect menu item for each opened window. Finally, on click of the button; we are calling Activate() to set focus to the selected window. Run the application and select Tools WinFormAddIn and the output will be as shown below.
![Toolbox]()
When we click on the button, it will set focus to that window. In this way, we can integrate win forms using DTE2 events and methods.
I am ending up with the things here. I am attaching the source code for reference. I hope this article will be helpful for all.