自己做的 VS.net 2005 sp1 程序注释使用的宏代码

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

主要功能是在代码头写注释和分组,大家可以参考了继续 

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 完工

到代码里测试下这两个按钮的功能吧。

好的代码注释是一个好的开始,我个人比较喜欢伪代码注释,也就是先写注释再写代码,这样思路不容易混,不用边写边想思路,注释先于代码,写得轻松,看得轻松。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值