This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Objectives and Learning Areas: For this Assignment you will be tested on the following areas:
1. What is Event Driven Programming (EDP)
2. How EDP works
3. How to add code to certain events of some controls
4. Understand KeyPressed Events
5. Understand Mouse Events
Introduction While your computer is on and running, there is something happening. It is either on the screen or in the
background. So there are always events taking place during the execution of any application.
To better understand event driven programming, please read the notes on the last page taken from a website
(http://www.husseinsspace.com/teaching/udw/1996/cnotes/chapsix.htm) and explains how even driven
programming works.
Event Driven Programming Illustrated Here is some graphics to illustrate how to add events during design time and how events works during runtime.
Adding an Event on a control during design time The diagram below shows how you can add an event during design time and how to add code to these events. As
can be seen from the Properties Windows, there is a whole range of events that takes place on the button only.
Other controls also have their own set of events. Mouse events are those events that take place while working with
the mouse and how the mouse interacts with the application
Calculate Button Click Event Executed During Runtime When the application is running the code is executed as a particular event takes places. In the case of the above
example, the Button Click event will call the Click method for that particular button.
Keyboard Events During the execution of an application, the user can press shortcut keys to perform certain functions or actions. In
order to alert the current form that a shortcut key will be pressed during runtime, the programmer must set the
KeyPreview property on the Form to true. This will register keyboard events for the controls on the form and for the
form itself.
For example, if you want to alert the application that a certain keyboard key will be pressed during runtime, you first
step is to set the KeyPreview property of the Form1 to true.