Post

VS.NET Macro - Region Marker

This is a pretty useful macro to add to the IDE. It allows you to mark a region of your code, activate this macro and it will enclose the marked area in a #region block.

1
2
3
4
5
6
7
8
9
10
Sub OutlineSelection()

  Dim objTextDoc As TextDocument
  Dim title As String = InputBox("Enter the title for the #Region", "#Region code")
  objTextDoc = DTE.ActiveDocument.Object("TextDocument")
  objTextDoc.Selection.Insert("#Region """ & title & "" & vbNewLine, vsInsertFlags.vsInsertFlagsInsertAtStart)
  objTextDoc.Selection.Insert(vbNewLine & "#End Region ", vsInsertFlags.vsInsertFlagsInsertAtEnd)
  objTextDoc.Selection.SmartFormat()

End Sub

Thanks to Jason Tucker for pointing this out.

This post is licensed under CC BY 4.0 by the author.