actual .ppt file

Download Report

Transcript actual .ppt file

Our First Set of Objects
Ch 2





Form
Label
Textbox
Button
Picturebox
Overview-An Overview of Visual Basic .NET
1
Name Property
 All objects have a name property.
 Naming Convention (p11-13)
 Start with a letter
 Remaining chars. – letters, numbers, underscore
 No spaces, special symbols or punctuation
 Guidelines
 Prefix with 3 characters indicating type of control
 Use small case for prefix then capitalize the first
character after the prefix.
 Select names that are meaningful and clear
• Ex. btnCalculateGrossPay,
Overview-An Overview of Visual Basic .NET
lblEmployeeName
2
Key Form Properties
Property
Description
Text
Caption displayed in the title bar
Icon
Image displayed on Titlebar
StartPosition
Position of window on screen
Size, Location
Width/Height; Left/Top of window
FormBorderStyle
Resizeable, Fixed, etc.
MinimizeBox,
MaximizeBox,
ControlBox
Indicates via True/False whether these
features are desired
Windowstate
Normal, Minimized, Maximized
Overview-An Overview of Visual Basic .NET
Label Control
 Used to display data that users cannot change
Property
Description
Text
Displayed information
AutoSize
Determines if the object resizes
itself to display all Text
BorderStyle
None-Fixed Single 3D
Font
Characteristics of the displayed
Text (Tahoma, Sans Serif, Arial)
TextAlign
Governs placement of text within
the label
Overview-An Overview of Visual Basic .NET
4
Button Control
 Used to display data that users cannot change
Property
Description
Text,
Same as label
BackColor,FontC
olor, Font,
BorderStyle,
TextAlign
Overview-An Overview of Visual Basic .NET
5
Textbox Control
 Allows users to enter information
Property
Description
Text,
BackColor,FontColor,
Font, BorderStyle,
TextAlign
Same as for labels
MultiLine
Allows text entry on multiple lines
Scrollbars
Vertical or Horizontal
PasswordChar
Char to be displayed for password
input)
MaxLength
Limits number of chars to be
entered
Overview-An Overview of Visual Basic .NET
6
Picturebox Control
 To display a graphic
Property
Description
Image
The image to be displayed
SizeMode
Normal, stretchimage
Overview-An Overview of Visual Basic .NET
7
Changing the Property for
More Than One Control at a Time

You can change the property setting for multiple controls at the
same time by clicking one control and then pressing and holding
down the Control key as you click the other control in the form.

Note: This assumes that the controls are of the same type.

You can use the Control+Click method to select as many controls
as you want

To cancel the selection of one of the selected controls, press and
hold down the Control key as you click the control

To cancel the selection of all of the selected controls, release the
Control key, then click the form or an unselected control on the
form
Overview-An Overview of Visual Basic .NET
8
Using the Format Menu
 The Format menu provides options that allow you
to manipulate the controls in the user interface
 The Align option allows you to align two or more
controls by their left, right, top, or bottom borders
 You can use the Make Same Size option to make
two or more controls the same width or height, or
both width and height
 The Format menu also has a Center in Form
option that centers one or more controls either
horizontally or vertically on the form
Overview-An Overview of Visual Basic .NET
9
Starting and Ending an Application
You can start an application by
 Clicking Debug on the menu bar, and then clicking Start
 Or you can simply press the F5 key on your keyboard
 When you start an application, Visual Studio .NET
automatically creates a file that can be run outside of the
Visual Studio .NET IDE
 The file, referred to as an executable file, has the same
name as the project, but with an .exe filename extension. It
can be found in the application’s bin directory.
Overview-An Overview of Visual Basic .NET
10
Writing Visual Basic .NET Code
 Actions—such as clicking, double-clicking, and
scrolling—are called events
 The set of Visual Basic .NET instructions, or
code, that tells an object how to respond to an
event is called an event procedure
 A class definition is simply a block of code that
specifies (or defines) the attributes and behaviors
of an object
 When you start the application, Visual Basic .NET
uses the class definition to create the object
Overview-An Overview of Visual Basic .NET
11
The Code Window
Class
definition
Code Editor
window tab
Event
procedure
Overview-An Overview of Visual Basic .NET
12
Method btnDisplayDirections_Click
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
' Ends the application
Me.Close()
End Sub
Line Continuation Mark
Name of the event the procedure responds to
Name of the control that owns the event procedure
Marks the beginning of this event procedure
Overview-An Overview of Visual Basic .NET
13
Printing Your Code
 You always should print a copy of the code
entered in the Code Editor window, because
the printout will help you understand and
maintain the application in the future
 To print the code, the Code editor window
must be the active, or current, window
Overview-An Overview of Visual Basic .NET
15