Datasheet

32
CHAPTER 1 VISUAL STUDIO 2010
Code Regions
Source fi les in Visual Studio allow you to collapse blocks of code. The idea is that in most cases you can reduce
the amount of onscreen code, which seems to separate other modules within a given class, by collapsing the
code so it isn t visible; this feature is known as outlining . For example, if you are comparing the load and
save methods and in between you have several other blocks of code, then you can effectively hide this code,
which isn t part of your current focus.
By default, there is a minus sign next to every method (sub or function). This makes it easy to hide or show
code on a per - method basis. If the code for a method is hidden, the method declaration is still shown and
has a plus sign next to it indicating that the body code is hidden. This feature is very useful when you are
working on a few key methods in a module and you want to avoid scrolling through many screens of code
that are not relevant to the current task.
It is also possible to create custom regions of code so you can hide and show portions of your source fi les.
For example, it is common to see code where all of the properties are placed in one region, and all of the
public methods are placed in another. The
#Region directive is used for this within the IDE, though it has
no effect on the actual application. A region of code is demarcated by the #Region directive at the top and
the #End Region directive at the end. The #Region directive that is used to begin a region should include a
description, which appears next to the plus sign shown when the code is minimized.
The outlining enhancement was in part inspired by the fact that the original Visual Studio designers generated
a lot of code and placed all of this code in the main vb fi le for that form. It wasn t until Visual Studio
2005 and partial classes that this generated code was placed in a separate fi le. Thus the region allowed the
generated code section to be hidden when a source fi le was opened. Being able to see the underpinnings
of your generated UI does make it is easier to understand what is happening, and possibly to manipulate
the process in special cases. However, as you can imagine, it can become problematic; hence the
#Region
directive, which can be used to organize groups of common code and then visually minimize them.
Visual Studio 2010 developers, but not Express Edition developers, can also control outlining throughout a
source fi le. Outlining can be turned off by selecting Edit
Outlining Stop Outlining from the Visual Studio
menu. This menu also contains some other useful functions. A section of code can be temporarily hidden by
highlighting it and selecting Edit Outlining Hide Selection. The selected code will be replaced by ellipses
with a plus sign next to it, as if you had dynamically identifi ed a region within the source code. Clicking the
plus sign displays the code again.
Tear - Away Tabs
You may have noticed in Figure 1 - 15 that the Code View and Form Designer windows open in a tabbed
environment. This environment is the default for working with the code windows inside Visual Studio, but
you can change this. As with any other window in Visual Studio 2010, you can mouse down on the tab and
drag it to another location.
What makes this especially useful in Visual Studio 2010 is that you can drag a tab completely off of the main
window and have it open as a standalone window elsewhere. Thus, you can take the current source fi le you
are editing and drag it to a separate monitor from the remainder of Visual Studio examples of this are the
screens earlier in this chapter showing the project properties. If you review those images you ll see that they are
not embedded within the larger Visual Studio 2010 frame but have been pulled out into their own window.
Running ProVB_VS2010
Now that you ve reviewed the elements of your generated project, let s test the code before continuing. To
run an application from within Visual Studio, you have several options; the fi rst is to click the Start button,
which looks like the Play button on a tape recorder. Alternatively, you can go to the Debug menu and select
Start. Finally, the most common way of launching applications is to press F5.
Once the application starts, an empty form is displayed with the standard control buttons (in the upper -
right corner) from which you can control the application. The form name should be Professional VB.NET,
which you applied earlier. At this point, the sample doesn t have any custom code to examine, so the next
step is to add some simple elements to this application.
CH001.indd 32CH001.indd 32 4/5/10 11:56:49 AM4/5/10 11:56:49 AM