使用 vs2008 宏 Macro

通过宏实现自动插入当前系统时间、姓名及项目注释信息至代码指定位置,简化开发流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   使用 vs2008  的宏 Macro 来实现一个小小的功能,向代码指定位置插入当前系统时间的值,“alt+F8”打开宏编辑器,输入你想输入的代码

Public Module Module1

   Sub PrintDateTime()
        If (Not IsNothing(DTE.ActiveDocument)) Then
            Dim selection As TextSelection = DTE.ActiveDocument.Selection
            selection.Insert(DateTime.Now.ToString())
        End If
    End Sub
    Sub PrintMyName()
        If (Not IsNothing(DTE.ActiveDocument)) Then
            Dim selection As TextSelection = DTE.ActiveDocument.Selection
            selection.Insert("anders lu")
        End If
    End Sub
    Sub PrintXMLAnnotation()
        If (Not IsNothing(DTE.ActiveDocument)) Then
            Dim selection As TextSelection = DTE.ActiveDocument.Selection
            selection.Insert("功    能:")
            selection.NewLine()
            selection.Insert("作    者: anders lu")
            selection.NewLine()
            selection.Insert("创建时间:" + DateTime.Now.ToString())
            selection.NewLine()
            selection.Insert("修正履历:")
            selection.NewLine()
            selection.Insert("修正时间:")
        End If
    End Sub

End Module

这样在写代码的时候就可以使用它了,两步,第一步三个"/";第二步执行宏,结果如下:

 

        /// <summary>
        /// 功    能:
        /// 作    者: anders lu
        /// 创建时间:2011-8-5 17:43:22
        /// 修正履历:
        /// 修正时间:
        /// </summary>
        /// <typeparam name="Q"></typeparam>
        /// <returns></returns>


    我最近在使用代码段及代码模板在整理一些项目需要的东西,会陆续写成博客。。。。。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值