Recognize When a Component Has Been Added to a Form

 < Free Open Study > 

Recognize When a Form Has Been Added to the Project

I have found that many of the events that I would expect to fire when I add a form or a component do not fire. The ProjectItemsEvents ItemAdded event does not appear to fire when a new item is added to a project. Assuming this is the case, it then becomes more difficult to determine if a form has been added to the project.

One event that does fire without fail is the WindowActivated event of the DTE.WindowEvents object. With a little bit of creativity, you can examine the window to see if it is a Form Designer window and, if so, you can take further action to examine the form. For example, you can check to see if the name has been changed from its default name. You can implement a Form Property Prompter and prompt the user to set certain basic properties such as the Name and Text properties, FormBorderStyle, and so forth. If you do this, then when you encounter a form that still has a default name such as "Form1", you can assume that the form has just been added or that the user has not yet changed the default name. Of course, you should give the user a way to turn off the prompting, unless of course you intend to enforce some type of naming convention for all forms. Be aware that the WindowActivated event is firing every time you click a new window, so do as little coding as possible to determine if you are looking at the window that you want to manipulate.

 < Free Open Study > 

Writing Add-Ins for Visual Studio  .NET
Writing Add-Ins for Visual Studio .NET
ISBN: 1590590260
EAN: 2147483647
Year: 2002
Pages: 172
Authors: Les Smith © 2008-2017.
If you may any questions please contact us: