#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.
Syntax
The syntax for #Region is as follows:
'code region
#End Region
The identifier string requires the quotes and acts as the title of the region when it is collapsed. The region is collapsed by default.
To collapse and hide a section of code
-
Place the section of code between the #Region and #End Region statements, 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
Multiple #Region Blocks
The #Region block 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. #Region blocks also can be nested within other #Region blocks.
Note Hiding code does not prevent it from being compiled, and will not affect the #If...#End If statements.

Join the conversation! Your thoughts help the community grow.