Expand And Collapse Code Blocks On The Fly In Visual Studio
Có thể bạn quan tâm
We all are very much familiar with #region in Visual Studio that let us specify a block of code to categorized and allow to expand and collapse. With having a region name given, it is often easier to segregate the code module and keep on the code block which is required. While you can have defined regions for different code block, often for a larger files you many need to focus on specific set of code and you don’t want to have separate region name for them. In that case, you can just simply collapse them on the fly and use them as long as you need them.
Here is the steps to follow:
- Select the section of code
- Press Ctrl+M+H – Turn on the collapsible/expandable option
- Press Ctrl+M+U – Turn off the the collapsible/expandable option.
Related Tip: Surround generated code with #region while implement Interface
- Here is how it looks like..

To remove the option you really don’t need to select the section back again. You can just place the cursor anywhere in the defined block and press the Ctrl+M+U option to remove the options.
Related Tip : How to select Block of Code in Visual Studio?
This works well as similar to other collapsible panel in Visual Studio code editor. You can just move hover on it to get a preview of the content.

This is really interesting feature and can make your code navigation very easy and faster.
Hope this helps !
Share on X (Twitter) Share on Facebook Share on Pinterest Share on LinkedIn Share on Email Previous Post Creating Custom Controls in Xamarin.Forms on Android. Next Post Did you know– You can Drag-Drop & Copy-Paste code inside Watch Window in Visual Studio?Abhijit Jana
Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.
You Might Also Like:
5 Comments to “Expand and Collapse Code Blocks on the fly in Visual Studio”
-
Pingback: Compelling Sunday – 19 Posts on Programming and QA
-
Pingback: Dew Drop – February 15, 2016 (#2188) | Morning Dew
-
Pingback: Expand and Collapse Code Blocks on the fly in Visual Studio | Soykan OZCELIK TeknoBlog | Teknoloji ve Yazılıma Dair…
-
Pingback: The Morning Brew - Chris Alcock » The Morning Brew – #2032
-
Pingback: Visual Studio – Developer Top Ten for Feb 22nd, 2016 - Dmitry Lyalin
Comments are closed.
SearchSubscribe to Blog via Email
Enter your email address to subscribe to this blog and receive notifications of new posts by email.
Email Address
Subscribe
Join 5,128 other subscribers
Recent Posts
-
Azure AI Services in a Nutshell – A Developer’s Mind Map 7 months/ 0 Comments -
Native Model Context Protocol (MCP) support in n8n 8 months/ 0 Comments -
The Evolution of LLM Integration 8 months/ 0 Comments -
Exploring the .NET Ecosystem: A Visual Mind Map 10 months/ 0 Comments -
From Request to Response: How APIs Work – Beginners Guide 2 years/ 0 Comments
Archives
Archives Select Month May 2025 (1) April 2025 (2) February 2025 (1) March 2024 (3) February 2024 (3) December 2023 (1) August 2023 (1) October 2022 (1) July 2022 (2) June 2022 (2) April 2022 (1) February 2022 (2) January 2022 (1) July 2021 (3) June 2021 (12) May 2021 (17) April 2021 (1) March 2021 (2) February 2021 (1) November 2020 (2) October 2020 (5) September 2020 (1) August 2020 (1) July 2020 (11) June 2020 (30) May 2020 (3) April 2020 (3) March 2020 (1) February 2020 (3) January 2020 (4) December 2019 (2) October 2019 (1) September 2019 (2) May 2019 (1) April 2019 (3) January 2019 (2) August 2018 (7) July 2018 (31) June 2018 (30) May 2018 (31) April 2018 (18) March 2018 (4) February 2018 (9) January 2018 (8) December 2017 (1) November 2017 (7) October 2017 (2) August 2017 (8) July 2017 (9) May 2017 (2) January 2017 (2) September 2016 (1) August 2016 (3) July 2016 (6) June 2016 (5) May 2016 (8) April 2016 (7) March 2016 (10) February 2016 (18) January 2016 (32) December 2015 (10) November 2015 (10) October 2015 (13) September 2015 (9) August 2015 (17) July 2015 (18) June 2015 (10) May 2015 (8) April 2015 (1) March 2015 (1) February 2015 (2) January 2015 (3) December 2014 (9) November 2014 (2) October 2014 (2) September 2014 (1) July 2014 (2) June 2014 (1) May 2014 (2) April 2014 (4) March 2014 (6) February 2014 (8) January 2014 (20) December 2013 (6) November 2013 (7) October 2013 (8) September 2013 (22) August 2013 (23) July 2013 (6) January 2013 (1) December 2012 (1) June 2012 (10) February 2012 (1) January 2012 (8) December 2011 (5) November 2011 (9) October 2011 (16) September 2011 (25) August 2011 (31) July 2011 (15) June 2011 (18) May 2011 (11) April 2011 (24) March 2011 (28) February 2011 (22) January 2011 (31) December 2010 (14)Editor's Pick
Từ khóa » Visual Studio Close All Code Blocks
-
Visual Studio - Command To Collapse All Sections Of Code?
-
Collapse And Expand Regions Of Code - Visual Studio (Windows)
-
How To Collapse All In VS Code - Alphr
-
Expand/Collapse All - Visual Studio Tips
-
Collapse All Functions Visual Studio Code Code Example
-
Collapse All Code Blocks Visual Studio Code Example - Code Grepper
-
VS Code: Collapse-and-Expand - DEV Community
-
How To Quickly Collapse Code Blocks In VSCode - LinuxPip
-
VS Code: How To Collapse/Expand Blocks Of Code - Kindacode
-
How To Collapse (minimize) And Expand All Code Blocks ... - YouTube
-
Keyboard Shortcuts For Visual Studio Code - UseTheKeyboard
-
[PDF] Keyboard Shortcuts For MacOS - Visual Studio Code
-
Basic Editing In Visual Studio Code
-
Fold Code Elements | JetBrains Rider