- Select Tools \ Macros \ Macros IDE.
- In the Project Explorer (within the Macros IDE), double click MyMacros \ Module1.
- Paste the following codes into the editor.
After that, close the Macros IDE. Now, you may customize the shortcut key to execute the Macro.
- Select Tools \ Customize from VS menu.
- Click Keyboard button (next to the Close button).
- In the "show command containing" field, type "PrintDateTimeSingleLine". This will shortlist the commands that is accessible through VS.
- In the "Press shortcut keys" field, press CTRL+0 and click Assign button.
- Click OK button to save the customized keyboard settings.
- In the coding editor, press CTRL+0 and VS will execute the Macro. So, you don't have to repeatly typing the current date/time for the comments anymore.
Sub PrintDateTime()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert(DateTime.Now.ToString("d.MMM.yyyy, ddd @ hh:mm"))
End If
End Sub
Sub PrintDateTimeSingleLine()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("//" & DateTime.Now.ToString("d.MMM.yyyy") & "-lhw-")
End If
End Sub
Sub PrintDateTimeProcHeader()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert(DateTime.Now.ToString("d.MMM.yyyy") & "-lhw")
selection.NewLine()
selection.Insert("-")
End If
End Sub
Sub PrintSeparator()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("//-----------------------------------------------------------------------")
End If
End Sub
Sub PrintHeavySeparator()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("//=======================================================================")
End If
End Sub
Sub PrintShortSeparator()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("//-------------------------------------")
End If
End Sub
Sub PrintNotice()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("//<======")
End If
End Sub
No comments:
Post a Comment