Tutorials to .com

Tutorials to .com » Dotnet » Control-and-components » Visual Studio.NET in the use of custom plug-ins to maximize your productivity (b)

Visual Studio.NET in the use of custom plug-ins to maximize your productivity (b)

Print View , by: iSee ,Total views: 15 ,Word Count: 651 ,Date: Thu, 21 May 2009 Time: 1:35 PM

A simple editing functions: Insert Date

I created a simple function to insert the date, the exact function is: in the current cursor position or the place where the currently selected text to insert the current date. This is the Visual Studio. NET already contains a macro to achieve this functionality with examples. So you can see macros and plug-ins through two different methods to achieve the same function. This example is very simple, you only need to modify a list in front of the Exec function. Through the previous chapters I have already created a basic plug-ins, the plug-in name is "TextUtil" said to be more precise "TextUtil.Connect.TextUtil". Exec function in the wizard to replace my auto-generated code.

handled = true;


handled = InsertDate ();

Add the following InsertData () function, you can Connect object to increase the function anywhere.

private bool InsertData ()


if (applicationObject.ActiveDocument! = null)

((TextSelection) applicationObject.ActiveDocument.Selection). Text

= DateTime.Now.ToString ( "yyy-MM-dd");

return true;


InsertData function and Sytem.String used System.DateTime object. Presentation on the System.String can see to help. I have noticed here in the OnConnection on three lines of code CommandBars, which after three lines of code in the process of running the Tools menu to create a menu item.

In addition to the name of plug-ins have been completed. Press F5 to test plug-ins. A new instance of the IDE is running, in this instance the plug-ins will appear in the Tools | Add-In Manager dialog box. Can then select Add-In Manager dialog box to the left to load plug-ins. Now you can open any text file, and then Visual Studio. NET command window, type "TextUtil.Command.TextUtil" in the current cursor position to insert the current date. In fact, before you enter the auto-complete variation of the order has been filled days.

When you press F5 to start running a new instance of the IDE, you plug in the debug mode. We can be found in the debug mode, all the abnormal information. Operation in general there have been any abnormal, they may not be available. As much as possible information to be abnormal, then the error will be found as soon as possible.

Change the command name

Wizard menu command has been designated as the default name (TextUtil). Therefore, this name does not have characteristics as described, I will be adding more menu commands, menu commands to change the name. At the same time, because I change the order in time to come across the name of the name confusion, so we must recognize our plug-ins do not have the same command name.

The first change is in the function call OnConnection of the AddNameCommand

Command command = commands.AddNamedCommand (addInInstance,


"Insert Current Date",

"Insert Current Date",

true, 59, ref contextGUIDS,

(int) vsCommandStatus.vsCommandStatusSupported

+ (int) vsCommandStatus.vsCommandStatusEnabled);

Change in QuertyStatus as follows:

if (commandName.ToLower () == "textutil.connect.insertdate")

Wizard running in the initial load should be registered before the plug-in information, but the impact of a change of name registration information. This means that the plug-in features to increase the time we need to generate new projects and the installation of plug-in project. And then run the installation process.

Figure 3 is running plug-ins (the original: Running the Macro Translator: It may be wrong)

Now "TextUtil.Connect.InsertDate" command can be in accordance with the idea of my work (Figure 3). However, how he work? Let us continue to look down.

.Net Control and components Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.