【问题标题】:Visual Studio 2012 - How to automate open close curly brace?Visual Studio 2012 - 如何自动化打开关闭花括号?
【发布时间】:2013-06-19 12:21:43
【问题描述】:

在 Visual Studio 2012 中,我创建了一个宏来创建一个左大括号、创建一个新行、创建一个新行、创建右大括号并将光标向上移动一行,然后是一个 TAB。

该宏与 Ctrl + 0 相关联,因此在 Ctrl + 0 之后我准备好了写代码。

如何在没有我的宏的 Visual Studio 2012 中做同样的事情?

【问题讨论】:

  • 感谢费边。我快速而肮脏地创建了一个插件。将其放入 Exec(...) TextSelection objSel = (EnvDTE.TextSelection)(_applicationObject.ActiveDocument.Selection); objSel.NewLine(); objSel.Insert("{"); objSel.Indent(); objSel.NewLine(); objSel.NewLine(); objSel.Insert("}"); objSel.Indent(); objSel.LineUp(); objSel.Indent(); objSel.SmartFormat(); objSel.LineUp();

标签: c# visual-studio-2012 macros editor


【解决方案1】:

这是从 MSDN 的 Visual Studio Gallery 免费下载的。 我想你会发现这可以解决问题。

http://visualstudiogallery.msdn.microsoft.com/8e2103b6-87cf-4fef-9410-a580c434b602

【讨论】:

    【解决方案2】:

    这是我添加到创建prj的向导中:在VS2012中安装并关联组合键:SHIFT+ALT+0

    public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if(commandName == "CurlyBraces.Connect.CurlyBraces")
                {
                    if (_applicationObject.ActiveDocument != null)
                    {
                        TextSelection objSel = (EnvDTE.TextSelection)(_applicationObject.ActiveDocument.Selection);
    
                        objSel.NewLine();
                        objSel.Insert("{"); objSel.Indent();
                        objSel.NewLine();
                        objSel.NewLine();
                        objSel.Insert("}"); objSel.Indent();
                        objSel.LineUp();
                        objSel.Indent();
                        objSel.SmartFormat();
                        objSel.LineUp();
                    }
    
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-24
      • 1970-01-01
      • 2012-06-18
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 2012-01-18
      相关资源
      最近更新 更多