LESSON 1 - Event-Driven Programming
LESSON 1 - Event-Driven Programming
Programming
Lesson 1
1
2
Learning Objectives
1. Describe Event-Driven Programming
2. Define Visual Basic ( VB )
3. Identify Benefits of using Visual Basic
4. History of Visual Basic
5. Describe the process of visual program design and development.
6. List and describe the three steps for writing a Visual Basic project.
7. Describe the various files that make up a Visual Basic project &
identify the elements in the Visual Studio environment.
8. Design a user interface by following the instructions in the given
problems.
3
Event-Driven Programming
currently the default paradigm in software engineering.
it uses events as the basis for developing the software.
These events can be something the users are doing
clicking on a specific button
picking an option from drop-down
typing text into a field,
giving voice commands,
or uploading a video
or system-generated events such as a program loading.
4
Event-driven Programming
is designed to react.
5
Event-driven programming
isa programming paradigm in which the flow of program
execution is determined by events
for example a user action such as a mouse click, key press, or a
message from the operating system or another program.
An event-driven application is designed to detect events as
they occur, and then deal with them using an appropriate
event-handling procedure.
The idea is an extension of interrupt-driven programming of
the kind found in early command-line environments such as
DOS, and in embedded systems (where the application is
implemented as firmware).
11
Event-driven programs
can be written in any programming language, although some
languages(Visual Basic for example) are specifically designed
to facilitate event-driven programming, and provide an
integrated development environment (IDE) that partially
automates the production of code, and provides a
comprehensive selection of built-in objects and controls, each
of which can respond to a range of events.
Virtually all object-oriented and visual languages support
event-driven programming.
Visual Basic, Visual C++ and Java are examples of such
languages.
12
Background
Before the arrival of object-oriented programming languages, event
handlers would have been implemented as subroutines within a
procedural program.
The flow of program execution was determined by the programmer,
and controlled from within the application’s main routine.
The complexity of the logic involved required the implementation
of a highly structured program.
All of the program’s code would be written by the programmer,
including the code required to ensure that events and exceptions
were handled, as well as the code required to manage the flow of
program execution.
15
An Introduction to Visual
Basic 2010
Why Windows and Why Visual Basic
How You Develop a Visual Basic Application
The Different Versions of Visual Basic
18
select
click on OK button
26
Toolbox
28
text box
sizing handles
31
Properties Window
Press F4 to
display the
Properties
window for the
selected control.
properties settings
Description pane
33
Setting Properties
Click on property name in left column.
Enter its setting into right column by typing or
selecting from options displayed via a button or
ellipses.
35
1. Click on ForeColor.
2. Click on button at right of
settings box.
3. Click on Custom tab to
obtain display shown.
4. Click on a color.
36
Font Property
1. Click on Font in left
column.
2. Click on ellipsis at right
of settings box to obtain
display shown.
3. Make selections.
37
Button Control
The caption on the button should indicate the
effect of clicking on the button.
Text property
38
Label Control
Used to identify the contents of a text box.
Text property specifies caption.
By default, label automatically resizes to
accommodate caption on one line.
When the AutoSize property is set to False, label
can be resized manually. AutoSize is used
primarily to obtain a multi-rowed label.
40
Fonts
Proportional width fonts, such as Microsoft Sans
Serif, use less space for "I" than for "W"
Fixed-width fonts take up the same amount of
space for each character – like Courier New
Fixed-width fonts are used for tables.
45
Auto Hide
Hides Toolbox when not in use
Vertical push pin icon indicates auto hide is
disabled.
Click the push pin to make it horizontal and enable
auto hide.
push pin
46
Positioning Controls
proximity
line
47
snap line
48
snap line
49
Tab Order
Event
An event is an action, such as the user clicking on
a button
Usually, nothing happens in a Visual Basic
program until the user does something and raises
an event.
What happens is determined by statements inside
the event procedure.
52
Sample Statements
txtBox.ForeColor = Color.Red
txtBox.Visible = True
txtBox.Text = "Hello World"
General Form:
controlName.property = setting
53
Sample Form
txtFirst
txtSecond
btnRed
54
Focus
When you click on a text box, a cursor appears in
the text box, and you can type into the text box.
Such a text box is said to have the focus.
If you click on another text box, the first text box
loses the focus and the second text box receives
the focus.
55
Examples of Events
btnShow.Click
txtBox.TextChanged
txtBox.Leave
General Form:
controlName.event
56
Code Editor
Code Editor tab Form Designer tab
58
Sample Form
txtFirst
txtSecond
btnRed
txtFirst.TextChanged
txtFirst.ForeColor = Color.Blue
End Sub
End Class
63
IntelliSense
Automatically pops up to help the programmer.
txtFirst.
64
Code Editor
click tab to return to Form Designer
65
Sample Form
txtFirst
txtSecond
btnRed
Activity
Design a graphical user interface by following the
instructions carefully.