How to: Collapse and Hide Sections of Code (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
#Region directive enables you to collapse and hide sections of code in Visual Basic files. The
#Region directive lets you specify a block of code that you can expand or collapse when using the Visual Studio code editor. The ability to hide code selectively makes your files more manageable and easier to read. For more information, see Outlining.
#Region directives support code block semantics such as
#If...#End If. This means they cannot begin in one block and end in another; the start and end must be in the same block.
#Region directives are not supported within functions.
Place the section of code between the
#End Regionstatements, as in the following example:
#Region "This is the code to be collapsed" Private components As System.ComponentModel.Container Dim WithEvents Form1 As System.Windows.Forms.Form Private Sub InitializeComponent() components = New System.ComponentModel.Container Me.Text = "Form1" End Sub #End Region
#Regionblock can be used multiple times in a code file; thus, users can define their own blocks of procedures and classes that can, in turn, be collapsed.
#Regionblocks can also be nested within other
Hiding code does not prevent it from being compiled and does not affect