Visual Studio 2008 / Collapse & Expand Code
Subtitles of the Movie
Now let's talk about something that's kind of cool in Visual Studio and that is the ability to expand and collapse code. And while we're at it, I'm also going to show you another trick with commenting so let's talk about these expanding and collapsing code. You're going to notice that along the left side of the code window in Visual Studio you have these little minus boxes and what's happening here is these things will allow you to string code regions, OK? The first one that we'll do is notice our little Click Button Handler. Notice it starts here and goes to right here. OK? If I click on this little Minus Sign, it will collapse that so that all that code is not visible. But notice I can come up here in my comments. I can collapse those and I can come up here to my form and collapse that. OK? Notice on the class I can collapse the entire class. Now it's all still there but I can collapse it or expand it at will. Now, some people love this, some people hate it. Just figure out where you are on it and see what happens. Now, when you've been collapsing stuff here, you will notice that I can go up to File and chose Print and you'll notice that I can tell it to hide collapsed regions or to include line numbers. We'll leave that alone for now. But if I need to print out my code for any reason, I can hide collapsed regions and not print that out so that's kind of cool, little thing to know there. Now, there's another thing that I can do with these code regions and that is I can build my own code regions so let's say that for whatever reason I'm going to say I'll start right here. I want this comment and all of this stuff down here, all the way down to right about down here to be in a code region. All I have to do is put Pound Region. Then I can put out around it Mark's Code, OK? And then I will come down here to where I want it to end and I will put Pound End Region and you will notice that I just put in Region around this code and I can collapse that and all of it goes away and I can turn it back on. Some people like this when they're debugging, when they're trying to go back and create code or change code that was there, whatever, OK? So you can put these regions in however you'd like. Notice I can just highlight them and delete them and get rid of them if I don't like them. There are some ifs, ands and buts about code regions. You can go out and look on Google and chase some of that down. But there's one other thing I wanted to show you that's kind of along the line of code regions. Since I can use these things to expand and contract code and I can troubleshoot with them, there's another thing I wanted to point out to you that I could have mentioned in the comments but somehow I didn't. So I'll just throw them in here and that is I can highlight a whole group of code and up here and this is actually on the Toolbar and it is on the Text Editor Toolbar so if I turn on the Text Editor Toolbar if I don't have it, turn on Text Editor, you will notice that there is a Comment and an Uncomment so I can highlight a bunch of code, click on Comment and it will comment every one of those lines out. Then I can highlight those lines again and uncomment and it will take the comments off. So some cool things I can do here with my code and as you can see, we can work to make our code extremely readable, extremely useful, extremely organized and that is where we should be headed with our code, right? So use these tools however they make sense to you. Notice up here I'm using Systems. Let me just point this out. I can put all my usings; I can expand and collapse those. But use this however you see fit to help you organize your code, use it when you're debugging, whatever. But that is collapsing and expanding code. By default, you classes, your entire class will expand and collapse, your individual, notice your form information, your comments and your individual functions will automatically collapse and expand and then of course you can build your own regions. So I just wanted you to know about that functionality.
Tutorial Information
| Course: | Introduction to Microsoft C# 2008 |
| Author: | Mark Long |
| SKU: | 34046 |
| ISBN: | 1-935320-78-5 |
| Release Date: | 2009-10-09 |
| Duration: | 7 hrs / 76 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 