3.
01 Apply Controls Associated
With Visual Studio Form
COMPUTER PROGRAMMING I
Essential Standard and Objectives
Essential Standard 3.00 Apply Procedures To
Construct Windows Form
3.01 Apply Controls Associated With Visual Studio
Form (3%)
Starting Visual Studio
First Time Only:
1. Choose Default Environment Settings Dialogue Box
1. Pick the language you are using for the class.
2. Click on Start Visual Studio.
3. Microsoft Visual Studio will Load User Settings – Be
Patient.
This is the Start Page you will
see each time you open Visual
Studio.
Ways to Create a Project
1. File > New > Project
2. Click New Project
button
3. In Recent Projects,
Create: Project,
click Project
Creating a New Project
The New Project dialog box is displayed.
1. Choose your programming language
2. Choose the template
VB: Windows Application
3. Change the Name
4. Change the Location
to where you are
saving your work.
5. Click OK
Visual Basic Project Folder
Contains the name of your current project and the many
individual components which may be related to
the project.
includes a project file (.vbproj) and a solution file (.sln).
A project file contains information specific to a single
programming task.
A solution file contains information about one or more
projects.
Solution Explorer Window
Special Note:
If Your Visual Basic Project Only Contains One
Project (.vbproj) and One Solution (.sln), Opening
the Project is the Same as Opening the Solution .
For a Multi-Project Solution, Open the Solution File
Only.
Visual Studio Tools
The Visual Studio IDE Appears.
The Main Tools Visible Are:
1. Designer Window
2. Solution Explorer Window
3. Properties Window, and
4. The Toolbox
Solution
Explorer
Window
Toolbox
Properties
Window
Designer Window
The Solution Explorer Window
The Solution Explorer window displays a list of the
projects in the solution and the items contained in
the project.
View Code
Refresh
View Designer
Properties
My Project files
Show All Files
Source Code File
Designer Window
Designer Window
Contains a Form.
To Change the size of the Form
1. Click and Drag the Sizing Handles on the Corner of the Form
or
2. Change the Size Properties (Measured in Pixels) on the
Properties Window.
The Editor Window
This White Window Will Contain Your Program
Code.
Class Name List Method Name List
Contains all control Contains all methods
objects on form for the chosen object
Properties Window
The Properties Window is Utilized to Change the
Characteristics of Your Form During Design Time.
Some of the Object Properties You Can Change include:
Name
Font
AutoSize
BackColor
ForeColor
Enabled
Size
Text
The Toolbox
The Toolbox Contains the Controls for Designing a
Form.
The Toolbox Tab Appears on the
Left of the IDE.
To Make the Toolbox Visible,
Click Toolbox Tab and Click the
Virtual Push Pin.
View Menu > Toolbox
Click the Toolbox button.
The Toolbox Controls
Controls Are Objects Which Can Be
Placed on Your Form Using Either
the Double-Click or Click and Drag
Method.
Examples of Some Toolbox Controls:
Buttons
Labels
Option Buttons
Check Boxes
List Boxes, etc.
Common Controls
Button
clicked by the user to perform an action or group of actions.
TextBox
used to gather input from a user or to display text back to the user.
Label
used to display information to the user either to identify another
object, provide instructions, or display output.
ListBox
used to display a list of items for a user to select. Multiple items can
be selected.
Common Controls
ComboBox
A drop down menu that also allows a user to type in an entry or
select an option.
Combines a ListBox and a TextBox
CheckBox
Usually found in a group box
Allows users to provide multiple inputs to answer a question
RadioButton
Used with group boxes
Allows user to make only one choice from the options in the group.
PictureBox
used to display a picture or image to the user.
Adding a Control
• To add an object to a form
– Click a control in the Toolbox and then click the form
– The pointer shape displays an icon similar to the selected
control.
– There are snap-to lines that you can use for alignment.
• Moving an object
– Drag a control object to move it.
– You can select a group to move together
Designing a Form
Remember that a balanced and pleasing design to a
form is important.
Try to make your form appear as professional as
possible.
When applying background color to your form,
consider the user and/or culture.
The Windows Form
The Windows Forms are used as the base for
creating GUIs for programs.
A form can be a dialog, an MDI window(Multiple
Document Interface window), or a simple graphical
window element that appears on the desktop.
The form acts as a container for components and
controls.
Form Properties and Events
Common Properties Description
Accept Button Button that is clicked when Enter is
pressed
AutoScroll Boolean value that allows or
disallows scrollbars to appear when
needed
BackColor The background color of the form
FormBorderStyle Border style for the form(none,
single, 3D and sizable
Font Font text displayed on the form and
the default font of controls to be
added to the form
Text Text in the form’s title bar
Form Common Methods
Common Methods Description
Close Closes a form and release all
resources. A closed form
cannot be reopened
Hide Hides form(does not destroy
the form or release its
resources)
Show Displays the hidden form
Form Common Event
Common Event Description
Load Occurs before a form is
displayed for the user. The
handler for this event is
displayed in the editor when
the form is double-clicked
The general design process for creating
Windows application requires
Implementi
Generating a ng the event
Adding handler
Windows controls and
Form and (method
setting its that are
setting its properties
properties called in
response to
an event)
Label, Textboxes and Buttons
Label is normally used to hold text on the form.
Although there are several way to display text, the
Label control enables you to post messages on the
form that can be changed by setting the Label’s text
property.
Textbox is used either to display a text or accept
input from the user.
A button is the corner stone of almost all Windows
application. With this control, a user can activate an
event that calls a method or a procedure.
Common Label Description
Properties
Font The font is used by the
text on the label
Text The text that appears on
the label
Text Align The alignment of the
Label’s text on the control
Textbox Properties and Events Description
AcceptsReturn Gers or sets a value indicating
whether pressing ENTER in a
multiline Textbox control creates a
new line of text in the control or
activates the default button for the
form
Multiline Gets or sets value indicating
whether this is a multiline Textbox
control
PasswordChar Gets or sets the charater used to
mask a characters of a password in
a single-line Textbox control
ReadOnly If set to True, the text cannot be
edited. The default value is false
ScrollBars For multiline textboxes, indicating
which scrollbars appear
Text The text box text content
Textbox event Description
TextChanged Generated when text changes in
Textbox(ex. When the user adds or
deletes characters). When a
programmer double-click the
Textbox control in Design view, an
empty event handler for this event
is generated
Button property and event Description
Text Specifies text displayed on the
Button face
Click Generated when the user click the
control. When a programmer
double-click the Button in design
view, an empty event handler for
this event is created.