且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

宏在Visual Studio中使用标记包装选定的文本

更新时间:2023-08-21 11:51:16

这样做的代码相当简单:

The code to do so is rather simple:

Sub SurroundWithStrongTag()
    DTE.ActiveDocument.Selection.Text = "<strong>" + DTE.ActiveDocument.Selection.Text + "</strong>"
End Sub

现在,如果您对宏不太了解,请点击此处添加它:

Now, if you don't know much about macros here's how to add it:


  • 首先你需要打开宏IDE,点击工具 - >宏 - >宏IDE ...

  • 接下来,我们将为您的自定义宏添加一个模块。右键单击Project Explorer中的MyMacros,单击Add-> Add Module ...,键入相应的名称,然后单击Add。

  • 现在将函数粘贴到模块中,为您想要的任何其他标签制作副本

  • 保存并关闭宏IDE

  • First you need open the macros IDE, click Tools->Macros->Macros IDE...
  • Next, we will add a module for your custom macros. Right click on "MyMacros" in the Project Explorer, click Add->Add Module..., type in an appropriate name then click "Add".
  • Now paste the function inside the module, making copies for any other tags you want
  • Save and close the macros IDE

到将宏挂钩到一个按钮:

To hook the macro up to a button:


  • 单击工具 - >自定义...

  • 单击新建...,键入适当的名称,单击确定。应该可以看到一个空工具栏(您可能需要移动窗口才能看到它)

  • 单击命令选项卡,然后在类别中选择宏

  • 找到之前创建的宏并将它们拖到工具栏上

  • 右键单击按钮以更改设置(例如显示图标而不是文本)

  • Click Tools->Customize...
  • Click New..., type in an appropriate name, click OK. An empty toolbar should be visible (you may have to move the window to see it)
  • Click the Commands tab, and select "Macros" in categories
  • Find the macros created before and drag them over to the toolbar
  • Right click the buttons to change settings (such as displaying an icon instead of text)