be applied. Chapter 3 covers how you can change your default environment settings at a later stage.
An interesting fact about the splash screen is that while a large portion of Visual
Studio now uses WPF to display its content, the new splash screen in Visual
Studio 2010 is still done in native code so that it displays as soon as possible
after you start Visual Studio. A signifi cant amount of time went into hand crafting
the wave at the bottom of the splash screen, so make sure you marvel at it
whenever you ’ re sitting there patiently waiting for Visual Studio to load.
Figure 1 - 6
A tip for Visual Basic .NET developers coming from previous versions of Visual
Studio is that they should not use the Visual Basic Development Settings option.
This option has been confi gured for VB6 developers and will only infuriate
Visual Basic .NET developers, because they will be used to different shortcut
key mappings. We recommend that you use the general development settings,
because these will use the standard keyboard mappings without being geared
toward another development language.
The Visual Studio IDE .
7
the ViSuaL StuDiO iDe
Depending on which set of environment settings you select, when you click the Start Visual Studio
button you will most likely see a dialog indicating that Visual Studio is configuring the development
environment. When this process is complete, Visual Studio 2010 opens, ready for you to start work,
as shown in Figure 1-7.
Figure 1-7
Regardless of the environment settings you selected, you see the Start Page in the center of the screen.
However, the contents of the Start Page and the surrounding toolbars and tool windows can vary.
If you click the grey rounded rectangle with the text “ Download the latest
information for developers to the Start Page, ” this pulls down news items from an
RSS feed specifi ed in the environment settings you specifi ed. Each item is displayed
in summary within the rectangle, allowing you to click through to the full article.
You can customize this feed by changing the Start Page News Channel property on
the Environment . Startup node of the Options dialog, accessible via the Options
item on the Tools menu.
8 .
Chapter 1 A Quick Tour
Before you launch into building your first application, it’s important to take a step back and look at
the components that make up the Visual Studio 2010 IDE. Menus and toolbars are positioned
along the top of the environment, and a selection of subwindows, or panes, appears on the left,
right, and bottom of the main window area. In the center is the main editor space: whenever you
open a code file, an XML document, a form, or some other file, it appears in this space for editing.
With each file you open, a new tab is created so that you can toggle among opened files.
On either side of the editor space is a set of tool windows: these areas provide additional contextual
information and functionality. In the case of the general developer settings, the default layout
includes the Solution Explorer and Class View on the right, and the Server Explorer and Toolbox on
the left. The tool windows on the left are in their collapsed, or unpinned, state. If you click a tool
window’s title, it expands; it collapses again when it no longer has focus or you move the cursor to
another area of the screen. When a tool window is expanded, you see a series of three icons at the
top right of the window, similar to those shown in the left image of Figure 1-8.
Figure 1-8
If you want the tool window to remain in its expanded, or pinned, state, you can click the middle
icon, which looks like a pin. The pin rotates 90 degrees to indicate that the window is now pinned.
Clicking the third icon, the X, closes the window. If later you want to reopen this or another tool
window, you can select it from the View menu.
Some tool windows are not accessible via the View menu; for example, those
having to do with debugging, such as threads and watch windows. In most cases
these windows are available via an alternative menu item; in the case of the
debugging windows, it is the Debug menu.
The right image in Figure 1-8 shows the context menu that appears when the first icon, the down
arrow, is clicked. Each item in this list represents a different way of arranging the tool window. As
you would imagine, the Float option allows the tool window to be placed anywhere on the screen,
independent of the main IDE window. This is useful if you have multiple screens, because you
can move the various tool windows onto the additional screen, allowing the editor space to use
the maximum screen real estate. Selecting the Dock as Tabbed Document option makes the tool
window into an additional tab in the editor space. In Chapter 4, you learn how to effectively manage
the workspace by docking and pinning tool windows.
The Visual Studio IDE .
9
Developing, Building, Debugging, and Deploying
Your First application
Now that you have seen an overview of the Visual Studio 2010 IDE, this section walks through
creating a simple application that demonstrates working with some of these components. This is,
of course, the mandatory “Hello World” sample that every developer needs to know, and it can be
done in either Visual Basic .NET or C#, depending on what you feel more comfortable with.
1.
Start by selecting File . New . Project. This opens the New Project dialog, as shown in
Figure 1-9. If you have worked with earlier versions of Visual Studio you will notice that
this dialog has had a significant facelift. There is still the tree on the left side of the dialog
for grouping templates based on language and technology, but now there is also a search
box in the top-right corner. The right pane of this dialog displays additional information
about the project template you have selected. Lastly, you can select the version of the .NET
Framework that the application will target using the drop-down at the top of the dialog.
Figure 1-9
Select the WPF Application from the Templates area (this item exists under the root
Visual Basic and Visual C# nodes, or under the sub-node Windows) and set the Name to
GettingStarted, before selecting OK. This should create a new WPF application project,
which includes a single startup window and is contained within a GettingStarted solution,
as shown in the Solution Explorer window of Figure 1-10. This startup window has automatically
opened in the visual designer, giving you a graphical representation of what the
window will look like when you run the application. You will notice that the Properties
tool window has appeared at the bottom of the right tool windows area.
10 .
Chapter 1 A Quick Tour
Figure 1-10
2.
Click the Toolbox tool window, which causes the window to expand, followed by
the pin icon, which pins the tool window open. To add controls to the window, select the
appropriate items from the Toolbox and drag them onto the form. Alternatively, you can
double-click the item and Visual Studio automatically adds them to the window.
3.
Add a button and textbox to the form so that the layout looks similar to the one shown in
Figure 1-11. Select the textbox and select the Properties tool window (you can press F4 to
automatically open the Properties tool window). Change the name of the control to
txtToSay. Repeat for the Button control, naming it btnSayHello and setting the Content
property to Say Hello!
Figure 1-11
The Visual Studio IDE .
11
You can quickly locate a property by typing its name into the search field located beneath
the Name field. In Figure 1-11 “Conten” has been entered in order to reduce the list of
Properties so that it’s easier to locate the Content property.
You will also notice that after you add controls to the window, the tab is updated with an
asterisk (*) after the text to indicate that there are unsaved changes to that particular item.
If you attempt to close this item while changes are pending, you are asked if you want to
save the changes. When you build the application, any unsaved files are automatically saved
as part of the build process.
One thing to be aware of is that some files, such as the solution file, are modified
when you make changes within Visual Studio 2010 without your being given any
indication that they have changed. If you try to exit the application or close the
solution, you are still prompted to save these changes.
4. Deselect all controls and then double-click the button. This not only opens the code editor
with the code-behind file for this form, it also creates and wires up an event handler for the
click event on the button. Figure 1-12 shows the code window after a single line has been
added to echo the message to the user.
Figure 1-12
12 .
Chapter 1 A Quick Tour
5.
Before you build and execute your application, place the cursor somewhere on the line
containing Messagebox.Show and press F9. This sets a breakpoint — when you run the
application by pressing F5 and then click the “Say Hello!” button, the execution halts at
this line. Figure 1-13 illustrates this breakpoint being reached. The data tip, which
appears when the mouse hovers over the line, shows the contents of the txtToSay.Text
property.
Figure 1-13
The layout of Visual Studio in Figure 1-13 is significantly different from the previous
screenshots, because a number of new tool windows are visible in the lower half of the
screen, and new command bars are visible at the top. When you stop the application you
will notice that Visual Studio returns to the previous layout. Visual Studio 2010 maintains
two separate layouts: design time and run time. Menus, toolbars, and various windows have
default layouts for when you are editing a project, whereas a different setup is defined for
when a project is being executed and debugged. You can modify each of these layouts to suit
your own style and Visual Studio 2010 will remember them.
6.
The last step is to deploy your application. Whether you’re building a rich client application
using Windows Forms or WPF, or a web application, Visual Studio 2010 has the ability
to publish your application. Double-click the Properties node in Solution Explorer and
select the Publish node to display the options for publishing your application, as shown in
Figure 1-14.
Summary .
13
Figure 1-14
In Figure 1-14, the publishing folder has been set to a local path, but you can specify a
network folder, an IIS folder, or an FTP site instead. Once you have specified where you
want to publish to, clicking Publish Now publishes your application to that location.
SummarY
You’ve now seen how the various components of Visual Studio 2010 work together to build an
application. The following list outlines the typical process of creating a solution:
1.
Use the File menu to create a solution.
2.
Use the Solution Explorer to locate the window that needs editing and double-click the item
to show it in the main workspace area.
3.
Drag the necessary components onto the window from the Toolbox.
4.
Select the window and each component in turn, and edit the properties in the Properties
window.
5.
Double-click the window or a control to access the code behind the component’s graphical
interface.
14 .
Chapter 1 A Quick Tour
6.
Use the main workspace area to write code and design the graphical interface, switching
between the two via the tabs at the top of the area.
7.
Use the toolbars to start the program.
8.
If errors occur, review them in the Error List and Output windows.
9.
Save the project using either toolbar or menu commands, and exit Visual Studio 2010.
In subsequent chapters, you learn how to customize the IDE to more closely fit your own working
style, and how Visual Studio 2010 takes a lot of the guesswork out of the application development
process. You also see a number of best practices for working with Visual Studio 2010 that you can
reuse as a developer.
2
The solution explorer, Toolbox,
and Properties
what’s in this chaPter?
.
Arranging files with the Solution Explorer
.
Adding projects, items and references to your solution
.
Working with the Properties tool window
.
Include your own properties in the Properties tool window
In Chapter 1 you briefly saw and interacted with a number of the components that make up
the Visual Studio 2010 IDE. Now you get an opportunity to work with three of the most
commonly used tool windows — the Solution Explorer, the Toolbox, and Properties.
Throughout this and other chapters you see references to keyboard shortcuts, such as Ctrl+S.
In these cases, we assume the use of the general development settings, as shown in Chapter 1.
Other profiles may have different key combinations.
the solution exPlorer
Whenever you create or open an application, or for that matter just a single file, Visual Studio
2010 uses the concept of a solution to tie everything together. Typically, a solution is made up
of one or more projects, each of which in turn can have multiple items associated with it. In
the past these items were typically just files, but increasingly projects are made up of items that
may consist of multiple files, or in some cases no files at all. Chapter 6 goes into more detail
about projects, the structure of solutions, and how items are related.
16 .
chaPter 2 The SoluTion explorer, Toolbox, And properTieS
The Solution Explorer tool window (Ctrl+Alt+L) provides a
convenient visual representation of the solution, projects, and
items, as shown in Figure 2 - 1. In this figure you can see three
projects presented in a tree: a C# WPF application, a C# WCF
service library, and a VB class library.
Each project has an icon associated with it that typically
indicates the type of project and the language it is written in.
There are some exceptions to this rule, such as setup projects
that don’t have a language.