VS 2013 SDK:如何通过编辑器的上下文菜单开发可访问的扩展? [英] VS 2013 SDK: How to develop an extension accesible through the editor's contextmenu?

查看:24
本文介绍了VS 2013 SDK:如何通过编辑器的上下文菜单开发可访问的扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Visual Studio 2013.

Visual Studio Package 项目的项目向导提供了以下三个选项:

The project wizard of a Visual Studio Package project gives these three options:

然而,我假装做的是创建一个非常简单的扩展(修改选定的文本),它应该可以通过文本编辑器的上下文菜单中的命令访问,不是菜单命令,也不是工具窗口,也不是自定义编辑器(...我认为).

However, what I pretend to do is create a very simple extension (which modifies the selected text) and it should be accesible through a command from the contextmenu of the text-editor, not a menu command neither a tool window and neither a custom editor (...I think).

首先,我应该选择什么项目来满足我的需求?(我正在使用菜单命令).

Firstly, what is the project that I should select for my needs? (I'm using a menu command).

其次,修改扩展的行为以仅在文本编辑器的上下文菜单中添加它的必要步骤是什么?.

Secondly, what are the necessary steps to modify the behavior of the extension to add it only in the contextmenu of the text editor?.

推荐答案

private void CreateContextMenu()
{
    // Get a reference to the context menu of code windows.
    CommandBars commandBars = (CommandBars)applicationObject.CommandBars;
    CommandBar codeWindowCommandBar = commandBars["Code Window"];

    // Add a popup command bar.
    CommandBarControl myCommandBarControl = codeWindowCommandBar.Controls.Add(MsoControlType.msoControlPopup,
        System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

    CommandBarPopup myPopup = (CommandBarPopup)myCommandBarControl;

    // Change its caption
    myPopup.Caption = "My popup";

    // Add controls to the popup command bar
    CommandBarButton myButton = (CommandBarButton)myPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
    myButton.Caption = "Click Me";
    myButton.Click += myButton_Click;
}

void myButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
    MessageBox.Show("What's up?");
}

这篇关于VS 2013 SDK:如何通过编辑器的上下文菜单开发可访问的扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆