Event Handling - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Event Handling

Description:

Run the application. Opening A Form With Code ... A program can hide all of it's forms but still be running. ... if the program is run locally. We don't need to ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 20
Provided by: Dave6
Category:
Tags: event | handling | run | up

less

Transcript and Presenter's Notes

Title: Event Handling


1
Event Handling
  • Tonga Institute of Higher Education

2
Event Driven Programs
  • Event Driven Programs The program responds to a
    user event
  • Event - An action or occurrence detected by a
    program
  • User
  • Clicking a mouse button
  • Pressing a key
  • System
  • Running out of memory
  • An error occurring
  • For example, your program might work like this
  • Show a form with a welcome message. The form
    will also contain a textbox, OK button and
    instructions to enter their name and click the Ok
    button.
  • Wait for the user to respond
  • When the user performs an action,
  • If the user clicks the X in the top right corner,
    quit the program
  • If the user typed in their name and pressed the
    OK button, show a message that you are happy to
    meet them
  • Gives more freedom to the user. It reacts to the
    users actions
  • Gives user the impression that they are in
    control

3
Current Situation
  • We learned how to display a graphical user
    interface
  • However, it doesnt do anything
  • Event Something that is triggered by the user
    of a GUI
  • Handler Code that can detect and respond to
    events

4
Creating Events
  • VS.NET automatically creates events for you
  • Double clicking on the control will automatically
    create code to handle the most common event
  • Code in this place will be executed when the
    button is clicked
  • This place is called a subroutine

5
Demonstration
  • Creating the most common event for a control

6
Creating Uncommon Events - 1
  • To create an uncommon event
  • View the code
  • Select the control you wish to create an event
    for
  • Select the event you wish to create

7
Creating Uncommon Events - 2
  • To create an uncommon event
  • View the code
  • Select the control you wish to create an event
    for
  • Select the event you wish to create

8
Demonstration
  • Creating an uncommon event for a control

9
Creating Events
  • When you using the techniques previously
    discussed, VS .NET automatically creates events
    in your code.
  • If you want, you can create this code yourself

The Event handled
Name of the Control
Keyword indicates that this method handles an
event
10
Demonstration
  • Working with Event Code

11
MessageBox
  • An attention getter
  • Displays information to the user
  • Forces user to do something before continuing
  • MessageBox.Show("Hi")

12
Demonstration
  • Displaying a MessageBox when a button is clicked

13
Class Activity
  • Double Click on the button
  • Add the following code to the subroutine
  • MessageBox.Show("Hello World!")
  • Run the application

14
Opening A Form With Code
  • Sometimes, we need to open a form when an event
    occurs. (Example Open a student form when a
    button is clicked)

15
Demonstration
  • Opening a form with code

16
Hiding a Form vs. Exiting an Application
  • We can use events to hide and show forms
  • frmCustomer.visible false
  • This is different from exiting an application
  • Application.Exit
  • A program can hide all of its forms but still be
    running. In this case, the program is not usable
    and is needlessly using the computers resources
  • If we are using VS.NET, the program will always
    stop running when we press the stop button
  • However, when we are using the .exe file, we must
    use the task manager to shut down programs that
    are running without any forms showing

17
Demonstration
  • Hiding a Form vs. Exiting an Application

18
Error when Quitting a Program Due to Network
Configuration
  • Application.Exit does not work properly when a
    project is located on a network drive
  • You will get this error
  • It will work if the program is run locally
  • We dont need to worry about it

19
Demonstration
  • Error Demonstration
Write a Comment
User Comments (0)
About PowerShow.com