Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the function of inserting date in Visual Studio.NET

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to achieve the date insertion function in Visual Studio.NET. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This example is very simple and only requires you to modify the Exec function listed above. Through the previous chapter I have created a basic plug-in whose name is "TextUtil" or rather "TextUtil.Connect.TextUtil". I replaced the code automatically generated by the wizard in the Exec function.

Handled=true

Replace with

Handled=InsertDate ()

Add the following InsertData () function, which can be added anywhere in the Connect object.

PrivateboolInsertData () {if (applicationObject.ActiveDocumentdestroy null) ((TextSelection) applicationObject.ActiveDocument.Selection). Text = DateTime.Now.ToString ("yyy-MM-dd"); returntrue;}

The InsertData function uses System.DateTime and Sytem.String objects. For an introduction to System.String, see help. Here I notice three lines of code about CommandBars in OnConnection that will create menu items in the tools menu when I run them later. In addition to the name plug-in has been completed. Press F5 to test the plug-in. A new IDE instance runs, in which the plug-in will appear in the tool | add-in management dialog box. You can load the plug-in by selecting the leftmost check box in the add-in management dialog box. Now you can open any text file, and then type "TextUtil.Command.TextUtil" in the VisualStudio.NET command window to insert the current date at the current cursor location. In fact, the automatic mutation is already filled with commands before you finish typing.

When you press F5 to run a new instance of IDE, your plug-in is in debug mode. We can find all exception information in debug mode. If any exceptions occur in normal operations, they may not be available. Get abnormal information as much as possible, and the wrong cause will be found as soon as possible.

Visual Studio.NET changes the name of the command

The wizard has given the menu command a default name (TextUtil). So the name does not have a characteristic description. I will add more menu commands and change the name of menu commands later. At the same time, because I have encountered name confusion when changing the command name, we have to make sure that our plug-in will not have the same command name. * the change is where AddNameCommand is called in the OnConnection function

Commandcommand=commands.AddNamedCommand (addInInstance, "InsertDate", "InsertCurrentDate", "InsertCurrentDate", true,59,refcontextGUIDS, (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled)

The changes in QuertyStatus are as follows:

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

The wizard should have registered the plug-in information before the initial run load, but the name change affected the registration information. This means that when we add plug-in functionality, we need to re-build the plug-in project and the installation project. Then run the installer. Run the plug-in (original text: RunningtheMacro translator: may be an error)

Now the "TextUtil.Connect.InsertDate" command can work as I want.

This is the end of this article on "how to insert a date in Visual Studio.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report