主要功能是在代码头写注释和分组,大家可以参考了继续
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module MyMacros
Sub AddWriter()
DTE.ActiveWindow.Selection.StartOfDocument()
DTE.ActiveDocument.Selection.Text = "/**********************************************"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "程序员: 郑永丹 "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "修改日期: " & DateTime.Now.ToString("yyyy-MM-dd")
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "程序内容:"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = " "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = " "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = " "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = " "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "**********************************************/"
DTE.ActiveDocument.Selection.NewLine()
End Sub



Sub AddRegion()
Dim AddTextInfo As String() = New String(7) {"Private Object 私有对象", "Public Object 公有对象", "Private Var 私有变量", "Public Var 公有变量", "Public GETSET 公有属性", "Even Function 事件函数", "Private Method 私有方法", "Public Method 公有方法"}
Dim i As Integer = 0
For i = 0 To AddTextInfo.Length - 1
DTE.ActiveDocument.Selection.Text = "#region""" & AddTextInfo(i) & """"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "#endregion"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
Next
End Sub
End Module
使用方法
VS2005sp1 --IDE环境--Tool--Macros--Macros Explorer
选择 右键 复制代码过去 后保存退出
VS2005IDE环境 Tool--Customize--Commands--Macros 看到自己的两个功能了吧
把他们拉到工具栏,这个时候你是看不到的,继续在刚才的窗口
选择 Rearrange Commands--ToolBar--看到自己两方法 Modify Selection--Chang Buttion Image
ok 完工
到代码里测试下这两个按钮的功能吧。
好的代码注释是一个好的开始,我个人比较喜欢伪代码注释,也就是先写注释再写代码,这样思路不容易混,不用边写边想思路,注释先于代码,写得轻松,看得轻松。

本文介绍了一个用于Visual Studio 2005的宏,该宏可以自动在文件头部添加注释,并创建代码分组区域,有助于提高代码的可读性和维护性。
4806

被折叠的 条评论
为什么被折叠?



