Question how to collapse part of code?

kinki_2046

Member
Joined
Jun 8, 2011
Messages
23
Programming Experience
Beginner
Dear all,

I have wrote a lot of code in a part.
And this is look like messy.

So, how to collapse a part of code in vb.net?

Thanks.
 
not sure what version of VS you have and how your shortcuts are setup but i think for default you can try

ctrl-m, then ctrl-o to collapse all of the code
ctrl-m, then ctrl-l to expand all of the code

other shortcut keys, ones that might be of use, i use these alot
ctrl-k, then ctrl-c to comment selected
ctrl-k, then ctrl-u to uncomment

ctrl-shift-b to build

ctrl-k-x to bring up insert snippet


Visual Studio - Command to collapse all sections of code? - Stack Overflow
there are a bunch of other shortcuts that may help too, look it up on Google or something
 
Last edited:
If your code really does look messy then collapsing it is not the answer. The answer is to write it more neatly.

If the issue is that you have a lot of code and it's difficult to find what you need then collapsing code can help. First up, you can already collapse method and property definitions. If you want to collapse further then you can add regions. You can add something like this to your code file:
#Region "My Region"

    '...

#End Region
and then everything from the first line of that region to the last will be collapsed to a single line that displays only the string label.

Note that you can press Ctrl+M, Ctrl+O at any time to collapse everything.
 
Back
Top