Use C # To write some tips in the vs plug-in

Source: Internet
Author: User

Recently, I used C # To write a vs plug-in. The main function is to insert standard comment segments and some common code segments. During the development process, I encountered some problems, read some materials, and did some research. Here we will make a simple record for some of the minor issues, hoping to help.
(1) When determining connectMode in OnConnection, you must add ext_cm_AfterStartup.
If (connectMode = Extensibility. ext_ConnectMode.ext_cm_UISetup
| ConnectMode = Extensibility. ext_ConnectMode.ext_cm_Startup
| ConnectMode = Extensibility. ext_ConnectMode.ext_cm_AfterStartup) // this line will work when u choose addin in addin manager
In this way, the plug-in will be re-displayed only when the plug-in is selected in The Addin Manager of vs. In the general example, only the first two judgments are available.
(2) In QueryState, when setting state, use the following statement
If (the command you added)
{
If (the display conditions are met)
Status = (vsCommandStatus) vsCommandStatus. vsCommandStatusSupported | vsCommandStatus. vsCommandStatusEnabled;
Else
Status = (vsCommandStatus) vsCommandStatus. vsCommandStatusSupported;
}
Else
Status = (vsCommandStatus) vsCommandStatus. vsCommandStatusUnsupported;
In this way, the plug-in menu becomes grayed out when the conditions are not met.
(3) the method for judging the existence of the code window is
(ApplicationObject. ActiveWindow! = Null) & (applicationObject. ActiveWindow. Type = vsWindowType. vsWindowTypeDocument)
That is to say, there is an active window and its type is document type.
(4) how to insert characters in the document window is
TextSelection ts = (TextSelection) applicationObject. ActiveDocument. Selection;
EditPoint ep = ts. ActivePoint. CreateEditPoint ();

Ep. Insert (strCode );
Of course, you can also call other EditPoint methods to delete, replace, and so on.
It's almost as simple as using C # As a plug-in program. At the same time, I feel that the object model designed by Microsoft is really comfortable to use. If you can design such a good system during development, how nice it is, haha

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.