Objetct 2
Objetct 2
2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
1
6.10.2022
This book’s examples, screen captures and discussions are based on When you open Visual Studio it initially displays the Start Page (Fig.
the free Visual Studio Community 2015 running on Windows 10. 2.1).
The examples will work on full versions of Visual Studio as well— Depending on your version of Visual Studio, your Start Page may look
though some options, menus and instructions might differ. different.
From this point forward, we’ll refer to Visual Studio Community 2015 The Start Page contains a list of links to Visual Studio resources and
simply as “Visual Studio” or “the IDE.” We assume that you have some web-based resources.
familiarity with Windows. At any time, you can return to the Start Page by selecting View > Start
Page.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
2
6.10.2022
The Start Page links are organized into two columns. The Start Page’s right column contains links to various online
documentation and resources to help you get started with Visual
The left column’s Start section contains options for
Studio and learn about Microsoft programming technologies.
building new apps or working on existing ones.
To access more extensive information on Visual Studio, you can
The left column’s Recent section contains links to projects browse the MSDN (Microsoft Developer Network) Library at
you’ve recently created or modified. https://msdn.microsoft.com/library/dd831853
You also can browse the web from the IDE by selecting View > Other
Windows > Web Browser.
To request a web page, type its URL into the location bar (Fig. 2.2)
and press Enter
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
3
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
Visual Studio provides many templates—the project types that users can create
in Visual C# and other languages.
A Windows Forms Application is an app that executes within a Windows
operating system and typically has a graphical user interface (GUI).
Users interact with this visual part of the app.
To create a Windows Forms Application, under Templates select Visual C# >
Windows > Classic Desktop, then in the middle column select Windows
Forms Application.
Click OK to display the IDE in Design view (Fig. 2.4), which contains the
features that enable you to create an app’s GUI.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
4
6.10.2022
The rectangle in the Design area titled Form1 (called a Form) Each open document’s name is listed on a tab. To view a
represents the main window of the Windows Forms app. document when multiple documents are open, click its tab.
Each Form is an object of class Form in the .NET Framework Class
The active tab (the tab of the currently displayed
Library.
Apps can have multiple Forms (windows). document) is highlighted.
A Label typically contains descriptive text (for example, "Welcome to The active tab’s highlight color depends on the Visual Studio
Visual C#!"), and a PictureBox displays an image. theme—the blue theme uses a yellow highlight and the light
Visual Studio has many preexisting controls and other components you and dark themes use a blue highlight.
can use to build and customize your apps.
Collectively, the Form and controls make up the app’s GUI.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
Commands for managing the IDE and for developing, maintaining and
executing apps are contained in menus, which are located on the menu
bar of the IDE (Fig. 2.5).
The set of menus displayed depends on what you’re currently doing in the IDE.
Menus contain groups of related commands called menu items that,
when selected, cause the IDE to perform specific actions.
The menus depicted in Fig. 2.5 are summarized in Fig. 2.6.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
5
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
6
6.10.2022
You can customize which toolbars are displayed by selecting View >
Toolbars then selecting a toolbar from the list in Fig. 2.8.
Each toolbar you select is displayed with the other toolbars at the
top of the Visual Studio window.
You move a toolbar by dragging its handle
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
The IDE provides windows for accessing project files and customizing
controls. Each can be accessed by selecting its name in the View menu.
Visual Studio provides an auto-hide space-saving feature.
When auto-hide is enabled for a window, a tab containing the window’s name
appears along the IDE window’s left, right or bottom edge (Fig. 2.10).
Clicking the name of an auto-hidden window displays that window (Fig. 2.11).
Clicking the name again (or clicking outside) hides the window.
To “pin down” a window (that is, to disable auto-hide and keep the
window open), click the pin icon.
When auto-hide is enabled, the pin icon is horizontal
When a window is “pinned down,” the pin icon is vertical
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
7
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
8
6.10.2022
The solution’s startup project (shown in bold in the Solution By default, the IDE displays only files that you may need to edit—other
Explorer) is the one that runs when you select Debug > Start files that the IDE generates are hidden.
Debugging (or press F5) or select Debug > Start Without Debugging The Solution Explorer window includes a toolbar that contains several
(or press Ctrl + F5 key). icons.
For a single-project solution, the startup project is the only project. Clicking the Show All Files icon (Fig. 2.13) displays all the solution’s
When you create an app for the first time, the Solution Explorer files, including those generated by the IDE.
window appears as shown in Fig. 2.13. Clicking the arrow to the left of a node expands or collapses that node.
The Visual C# file that corresponds to the Form shown in Fig. 2.4 is Click the arrow to the left of References to display items grouped
named Form1.cs (selected in Fig. 2.13). under that heading (Fig. 2.14).
Visual C# files use the .cs file-name extension, which is short for “C#.” Click the arrow again to collapse the tree.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
9
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
If the Properties window is not displayed below the Solution Explorer, Fig. 2.16 shows Form1’s Properties window—you can view by
select View > Properties Window to display it. clicking anywhere in the Form1.cs [Design] window.
The Properties window contains the properties for the currently The left column lists the Form’s properties
selected Form, control or file in the IDE. The right column displays the current value of each property.
Properties specify information about the Form or control. You can sort the properties either
When you select a property, its description is displayed at the bottom alphabetically (by clicking the Alphabetical icon) or
of the Properties window. categorically (by clicking the Categorized icon).
The Properties window is crucial to visual app development.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
10
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
11
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
12
6.10.2022
The Form’s size is specified in pixels (that is, dots on the screen).
By default, a Form is 300 pixels wide and 300 pixels tall.
You can resize the Form by dragging one of its sizing handles (the
small white squares that appear around the Form, as shown in ).
As you drag the mouse, the IDE’s status bar (at the bottom of the
IDE) shows the current width and height in pixels.
You also can do this via the Form’s Size property in the Properties
window.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
13
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
14
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
15
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
16
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
17
6.10.2022
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
Select File > Save All to save the entire solution. In run mode, the app is executing, and you can interact
The solution file (which has the filename extension .sln) with only a few IDE features—features that are not available
contains the name and location of its project, and the are disabled (grayed out).
project file (which has the filename extension .csproj) Select Debug > Start Debugging to execute the app (or
contains the names and locations of all the files in the press the F5 key).
project. The IDE enters run mode and displays “(Running)” next to
If you want to reopen your project at a later time, simply the app’s name in the IDE’s title bar.
open its .sln file. Click the app’s close box (X) to terminate the app
© 2018 Pearson Education, Ltd. All Rights Reserved. © 2018 Pearson Education, Ltd. All Rights Reserved.
18
6.10.2022
19