P1 Key Features of Event Driven Programming: Events

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

P1 Key Features of Event Driven

Programming

Events
Events are actions that the program responds to. A simple event can be a
mouse click on a control.

Event Handlers
An event handler is the code that runs when an event occurs known as
sub routines in Visual basics. Event handlers are executed when a trigger
occurs done by the user. A button on a form is an object and when that is
pressed it will trigger the event handler which is the code written for the
program.

Trigger Functions
These are functions that decides which code runs when an event happens.

Every event has a trigger function that occurs on a control.

Event Loops
These are built into the program language and they are used to check if and
event has occurred. Event loops continually look for events waiting to happen.
Event loops can detect a button click, arrival of a packet over a local network or
even file creation.

Form Components
Forms contain controls known as objects that experience events. A form can
contain user interface components such as labels, buttons, list boxes, radio
buttons and textboxes. Forms are used to provide an input tool for users that is
functional and approachable.

What happens when an Event takes place

The user interacts with a graphical user interface by clicking on a form


component such as a button.
The event loop waits for an event to take place and when it does it
understands that the user has clicked on an object.
The trigger function then decides which event handler to run given input
from the user.
The event handler then runs the code.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtTotal.Text = Val(txtNumber1.Text) + Val(txtNumber2.Text)
End Sub
End Class

The event that triggers the event handler to run


is a click of the Add button. I have created a
basic calculator. The code above is the event
handler add it allows the user to enter two
numbers and add them together which will then
be displayed as the total.

You might also like