1 
What is Event Driven 
Programming? 
Visual Studio 
and 
VB.NET
2 
P1: Key Features of EDP 
1. Event loops 
2. GUI design (Forms & Controls 
3. Trigger functions 
4. Event handlers
3 
P2: Demonstrate the use of event 
driven tools and techniques 
Using Visual Studio and VB.NET language 
Demonstrate the development process with screenshots 
and code examples, to show the main choices available 
IDE Tools inc: 
GUI form design 
Add & edit controls 
Choice of triggers 
Code colour & dropdown 
Debugging tools 
 Error list 
 Breakpoints & step 
through code 
Coding Techniques inc: 
Variables and Datatypes 
 Const, Global, Local 
 Integer, boolean, decimal, 
string, date 
Selection 
 If...Else & Select...Case 
Loops 
 Fixed & Conditional
4 
Event Loops 
Programmers are often not aware of these: 
The Event loop keeps testing the user interface to see if 
anything has happened e.g. a button click or a key 
pressed. Open Task Manager to see which programs are running 
When an event is detected, it is passed to the list of 
identified trigger functions, which then launches a 
response to the event. 
The event handlers are the actual program code 
modules that are executed when a particular trigger has 
occurred. 
Other (non user) activities can also cause an event to 
trigger – typically used in networking and when reading 
from or writing to files.
5 
Event Loop 
1 User interacts with page 
2 An ‘event’ is triggered 
EVENT! 
The page’s appearance is 3 A code handler runs in response 
updated/modified as a result 
4
6 
Forms and Controls 
A GUI (graphical user interface) is what the user 
sees when the program runs and usually consists of 
one or several forms 
Event driven programming is particularly suitable for 
GUIs - uses WIMP system 
Windows, Icons, Menus, Pointers 
Programmer can assist user with intuitive interface, 
restrict input to a limited range, provide visual 
feedback and context-sensitive help 
Event driven programs respond to events triggered 
by the user via the mouse or keyboard
7 
Forms and Controls 
Common methods for user interaction include clicking 
the mouse or pressing a key 
Each form contains various controls which allow the 
user to interact with the program in different ways 
e.g. Buttons, Textboxes, Labels, Menus, Pictureboxes, Timers 
Wide choice of controls can be customised for use by 
Select from toolbar and drop onto the form 
change its properties in design view (text, image, visible) 
Show form design in IDE and choice of controls in toolbox 
Add different types controls to provide input and feedback 
inc. visual and non-visual controls (timer) 
Change the properties (inc Name) and explain purpose
8 
Trigger functions 
Event driven programs respond to events 
triggered by the user 
The programmer chooses which event(s) 
to respond to by selecting the appropriate 
trigger function. 
Every object has a range of trigger 
functions – one for each possible event 
Different controls have different events 
(events for a text box not the same for a 
button) 
A Button has a Click event, a GotFocus event, a 
MouseHover event etc 
Button events
9 
Trigger Functions 
Triggers can also come from unseen events e.g. Timer 
Double clicking a control will select its default event 
Timer1_Tick() 
MenuItem1_Click() 
Forms also have events inc: 
Load (open for first time, set default values) 
KeyDown (when the user presses a key) 
Demonstrate how to create trigger functions for different controls 
inc. mouse, keyboard and timer (control event) 
Show how to select different triggers for the same control 
Explain how trigger functions are used in your program
10 
Event Handlers 
An event triggers the appropriate event handler 
Event handlers contain the code that runs when an 
event occurs 
These event handlers are self-contained sections of 
code – also called Procedures or Subroutines 
VB.NET uses Sub/End Sub to start and end the code 
This allows the programmer to work on one event of 
one control at a time and makes testing easier
11 
Event Handlers 
Demonstrate and explain different coding techniques 
Variables 
 Different datatypes 
 Local and Global 
Selection 
 If...Else 
 Select...Case 
Loops 
 Fixed loop e.g. For...Next 
 Conditional loop e.g. Do...Loop While 
Show how IDE assists with coding and debugging 
 Pre-written code and drop-down lists showing choice of 
possible commands 
 Errors are highlighted and step through debugging
12 
Advantages 
Flexibility: 
Wide choice of controls and trigger functions - 
programmer can decide what will happen when 
Suitability for GUI: 
WIMP system (Windows, Icons, Menus, Pointers) 
Simplicity and Ease of development: 
Programmers can add and code one object at a 
time, using simple constructs 
Pre-written code and drop-down lists showing 
choice of possible commands 
Errors are highlighted and step through debugging
13 
Disadvantages 
Errors can be more difficult to spot than with 
simpler, procedural programs 
Programs with complex GUIs may be slower 
to load and run than simpler programs – 
particularly if RAM is insufficient 
Programs with too many forms can be very 
confusing and/or frustrating for the user
14 
Which control would a programmer 
use to….? 
Allow a Yes/ No answer only? 
Allow a wide range of keyboard input? 
Limit user input to the numbers 1, 2, 3 & 4? 
Allow a user to subtly change the colour or 
brightness selected in a graphics application 
Allow a user to access commands without the 
mouse, but using keyboard navigation only?

Event driven theory

  • 1.
    1 What isEvent Driven Programming? Visual Studio and VB.NET
  • 2.
    2 P1: KeyFeatures of EDP 1. Event loops 2. GUI design (Forms & Controls 3. Trigger functions 4. Event handlers
  • 3.
    3 P2: Demonstratethe use of event driven tools and techniques Using Visual Studio and VB.NET language Demonstrate the development process with screenshots and code examples, to show the main choices available IDE Tools inc: GUI form design Add & edit controls Choice of triggers Code colour & dropdown Debugging tools  Error list  Breakpoints & step through code Coding Techniques inc: Variables and Datatypes  Const, Global, Local  Integer, boolean, decimal, string, date Selection  If...Else & Select...Case Loops  Fixed & Conditional
  • 4.
    4 Event Loops Programmers are often not aware of these: The Event loop keeps testing the user interface to see if anything has happened e.g. a button click or a key pressed. Open Task Manager to see which programs are running When an event is detected, it is passed to the list of identified trigger functions, which then launches a response to the event. The event handlers are the actual program code modules that are executed when a particular trigger has occurred. Other (non user) activities can also cause an event to trigger – typically used in networking and when reading from or writing to files.
  • 5.
    5 Event Loop 1 User interacts with page 2 An ‘event’ is triggered EVENT! The page’s appearance is 3 A code handler runs in response updated/modified as a result 4
  • 6.
    6 Forms andControls A GUI (graphical user interface) is what the user sees when the program runs and usually consists of one or several forms Event driven programming is particularly suitable for GUIs - uses WIMP system Windows, Icons, Menus, Pointers Programmer can assist user with intuitive interface, restrict input to a limited range, provide visual feedback and context-sensitive help Event driven programs respond to events triggered by the user via the mouse or keyboard
  • 7.
    7 Forms andControls Common methods for user interaction include clicking the mouse or pressing a key Each form contains various controls which allow the user to interact with the program in different ways e.g. Buttons, Textboxes, Labels, Menus, Pictureboxes, Timers Wide choice of controls can be customised for use by Select from toolbar and drop onto the form change its properties in design view (text, image, visible) Show form design in IDE and choice of controls in toolbox Add different types controls to provide input and feedback inc. visual and non-visual controls (timer) Change the properties (inc Name) and explain purpose
  • 8.
    8 Trigger functions Event driven programs respond to events triggered by the user The programmer chooses which event(s) to respond to by selecting the appropriate trigger function. Every object has a range of trigger functions – one for each possible event Different controls have different events (events for a text box not the same for a button) A Button has a Click event, a GotFocus event, a MouseHover event etc Button events
  • 9.
    9 Trigger Functions Triggers can also come from unseen events e.g. Timer Double clicking a control will select its default event Timer1_Tick() MenuItem1_Click() Forms also have events inc: Load (open for first time, set default values) KeyDown (when the user presses a key) Demonstrate how to create trigger functions for different controls inc. mouse, keyboard and timer (control event) Show how to select different triggers for the same control Explain how trigger functions are used in your program
  • 10.
    10 Event Handlers An event triggers the appropriate event handler Event handlers contain the code that runs when an event occurs These event handlers are self-contained sections of code – also called Procedures or Subroutines VB.NET uses Sub/End Sub to start and end the code This allows the programmer to work on one event of one control at a time and makes testing easier
  • 11.
    11 Event Handlers Demonstrate and explain different coding techniques Variables  Different datatypes  Local and Global Selection  If...Else  Select...Case Loops  Fixed loop e.g. For...Next  Conditional loop e.g. Do...Loop While Show how IDE assists with coding and debugging  Pre-written code and drop-down lists showing choice of possible commands  Errors are highlighted and step through debugging
  • 12.
    12 Advantages Flexibility: Wide choice of controls and trigger functions - programmer can decide what will happen when Suitability for GUI: WIMP system (Windows, Icons, Menus, Pointers) Simplicity and Ease of development: Programmers can add and code one object at a time, using simple constructs Pre-written code and drop-down lists showing choice of possible commands Errors are highlighted and step through debugging
  • 13.
    13 Disadvantages Errorscan be more difficult to spot than with simpler, procedural programs Programs with complex GUIs may be slower to load and run than simpler programs – particularly if RAM is insufficient Programs with too many forms can be very confusing and/or frustrating for the user
  • 14.
    14 Which controlwould a programmer use to….? Allow a Yes/ No answer only? Allow a wide range of keyboard input? Limit user input to the numbers 1, 2, 3 & 4? Allow a user to subtly change the colour or brightness selected in a graphics application Allow a user to access commands without the mouse, but using keyboard navigation only?