Lab 7 Keyboard Event Handling Mouse Event Handling



Similar documents
Interaction: Mouse and Keyboard DECO1012

Mouse Event Handling (cont.)

Using C# for Graphics and GUIs Handout #2

Chapter 12 Mouse and Keyboard

GUI Components: Part 2

Canterbury Maps Quick Start - Drawing and Printing Tools

WPF Shapes. WPF Shapes, Canvas, Dialogs 1

Java Mouse and Keyboard Methods

Part 1 Foundations of object orientation

BUILDING APPLICATIONS USING C# AND.NET FRAMEWORK (OBJECT-ORIENTED PROGRAMMING, X428.6)

Portal Connector Fields and Widgets Technical Documentation

Introduction to Visual Basic and Visual C++ Introduction to Control. TextBox Control. Control Properties. Lesson 5

TUTORIAL 4 Building a Navigation Bar with Fireworks

NiceLabel Designer Standard User Guide

APPLYING BENFORD'S LAW This PDF contains step-by-step instructions on how to apply Benford's law using Microsoft Excel, which is commonly used by

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

BAR CODE 39 ELFRING FONTS INC.

Barcode Labels Feature Focus Series. POSitive For Windows

OBJECTIVE1: Understanding Windows Forms Applications

Solutions from SAP. SAP Business One 2005 SP01. User Interface. Standards and Guidelines. January 2006

Computer Basics: Tackling the mouse, keyboard, and using Windows

Unit 21 - Creating a Button in Macromedia Flash

Using Excel to find Perimeter, Area & Volume

Table of Contents TASK 1: DATA ANALYSIS TOOLPAK... 2 TASK 2: HISTOGRAMS... 5 TASK 3: ENTER MIDPOINT FORMULAS... 11

Get-Snap. Once you have installed the DataCAD 9.03 update, you are ready to take advantage of this new feature.

Creating Personal Web Sites Using SharePoint Designer 2007

Hypercosm. Studio.

User s Manual CAREpoint EMS Workstation D-Scribe Reporting System

Petrel TIPS&TRICKS from SCM

Chapter 3 Input Devices

OX Spreadsheet Product Guide

Microsoft Access 2010 Overview of Basics

Help Document for Step by step, how-to instructions for navigating and using the Savannah Area GIS viewer.

How to create buttons and navigation bars

The Keyboard One of the first peripherals to be used with a computer and is still the primary input device for text and numbers.

What s New V 11. Preferences: Parameters: Layout/ Modifications: Reverse mouse scroll wheel zoom direction

FLASH. Mac versus PC. Pixels versus Vectors Two kinds of images are in the digital world: bitmaps and vectors:

Quick Guide. pdoc Forms Designer. Copyright Topaz Systems Inc. All rights reserved.

BARCODE PRINTING SET UP BARCODE PRINTING

SEMTech Solutions. Leaders in Refurbished SEMs. SEMTech Solutions Windows 7 SOFTWARE CONTROL SYSTEM

VISUAL BASIC Controls. Version 1 Trg. Div., NIC HQRs

Getting Started Guide. Chapter 14 Customizing LibreOffice

Using SSH Secure File Transfer to Upload Files to Banner

Tutorial DOC-OEMCS8-TU-EN-25/01/06

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Excel 2007 Basic knowledge

In this example, Mrs. Smith is looking to create graphs that represent the ethnic diversity of the 24 students in her 4 th grade class.

Fixplot Instruction Manual. (data plotting program)

Introduction to the TI-Nspire CX

First Bytes Programming Lab 2

Creating a Form. A form is something that is created allowing users to enter information in a more visual manner than a datasheet view.

Getting Started With DraftSight A Guide For AEC Users

Using Anchors Drupal: Gold, Silver & Bronze

The Barcode Printing option may be purchased for an additional cost. You will receive a CD that you will use to activate this feature.

How To Create A Database For Employee Records In A Club Account In A Computer System In A Cell Phone Or Cell Phone With A Cell Computer (For A Cell)

Understand the Sketcher workbench of CATIA V5.

Grandstream XML Application Guide Three XML Applications

Randy Hyde s Win32 Assembly Language Tutorials (Featuring HOWL) #4: Radio Buttons

Fountas & Pinnell Online Data Management System. Manage. Main Navigation Manage Districts/Schools/Classes Manage Groups Manage Students Manage Account

Creating a Simple Visual C++ Program

Plotting: Customizing the Graph

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

CUSTOMER+ PURL Manager

Romanian Online Dialect Atlas: Crişana

GelAnalyzer 2010 User s manual. Contents

Fireworks CS4 Tutorial Part 1: Intro

Chapter 5 Objectives. Chapter 5 Input

8 CREATING FORM WITH FORM WIZARD AND FORM DESIGNER

Excel. Microsoft Office s spreadsheet application can be used to track. and analyze numerical data for display on screen or in printed

Introduction to Autodesk Inventor for F1 in Schools

Working With Animation: Introduction to Flash

Figure 3.5: Exporting SWF Files

Module 6: Validating User Input

Creating a Logo in CorelDRAW

Chapter 9 Input/Output Devices

S PT-E550W ELECTRONIC E C LABELING L SYSTEM

idisplay v.2.0 User Guide

Introduction to Microsoft Access and Visual Basic for Applications

How to Develop Accessible Linux Applications

VIDEO SCRIPT: Data Management

Windows PowerShell Essentials

Installing An ActiveX Control in InTouch

Visual Basic Programming. An Introduction

understand how image maps can enhance a design and make a site more interactive know how to create an image map easily with Dreamweaver

Tutorials Drawing a 555 timer circuit

ArchiCAD Tutorial Getting started. Dr. Benny Raphael Dept. of Building National University of Singapore (NUS)

AODA Mouse Pointer Visibility

Lesson 3 - Processing a Multi-Layer Yield History. Exercise 3-4

Creating Web Pages With Dreamweaver MX 2004

Virtual Mouse Using a Webcam

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Fireworks for Graphics and Images

BAR CODE 2 OF 5 INTERLEAVED

FAMOS 6.0 What s new?

2. More Use of the Mouse in Windows 7

Transcription:

Lab 7 Keyboard Event Handling Mouse Event Handling Keyboard Event Handling This section explains how to handle key events. Key events are generated when keys on the keyboard are pressed and released. These events can be handled by any control that inherits from System.Windows.Forms.Control. There are two types of key events. The first is event KeyPress, which fires when a key representing an ASCII character is pressed (determined by KeyPressEventArgs property KeyChar). ASCII is a 128-character set of alphanumeric symbols. (The full listing can be found in Appendix B, ASCII Character Set.) Using the KeyPress event, we cannot determine if modifier keys (such as Shift, Alt and Control) were pressed. To determine such actions, handle the KeyUp or KeyDown events, which form the second type of key event. Class KeyEventArgs contains information about special modifier keys. The key s Key enumeration value can be returned,giving information about a wide range of non-ascii keys. Modifier keys are often used in conjunction with the mouse to select or highlight information. The delegates for the two classes are KeyPressEventHandler (event argument class KeyPressEventArgs ) and KeyEventHandler (event argument class KeyEventArgs). Figure 12.31 lists important information about key events. Figure 12.32 demonstrates using the key event handlers to display the key that was pressed. The program s form contains two Labels. It displays the key pressed on one Label and modifier information on the other. The two Labels (named charlabel and keyinfolabel) are initially empty. The KeyDown and KeyPress events convey different information; thus, the form (Key-Demo) handles them both.

Example Code :

The KeyPress event handler (lines 28 32) accesses the KeyChar property of the KeyPressEventArgs object. This returns the key pressed as a char and displays in charlabel (line 31). If the key pressed was not an ASCII character, then the KeyPress event will not fire and charlabel remains empty. ASCII is a common encoding format for letters, numbers, punctuation marks and other characters. It does not support keys such as the function keys (like F1) or the modifier keys (Alt, Control and Shift). The KeyDown event handler (lines 35 45) displays more information, all from its KeyEventArgs object. It tests for the Alt, Shift and Control keys (lines 39 41), using the Alt, Shift and Control properties, each of which returns bool. It then displays the KeyCode, KeyData and KeyValue properties. The KeyCode property returns a Keys enumeration, which is converted to a string using method ToString. The KeyCode property returns the key that was pressed, but does not provide any information about modifier keys. Thus, both a capital and a lowercase a are represented as the A key. The KeyData property returns a Keys enumeration as well, but includes data about modifier keys. Thus, if A is input, the KeyData shows that the A key and the Shift key were pressed. Lastly, KeyValue returns the key code for the key that was pressed as an integer. This integer is the Windows virtual key code, which provides an integer value for a wide range of keys and for mouse buttons. The Windows virtual key code is useful when testing for non-ascii keys (such as F12). The KeyUp event handler clears both labels when the key is released (lines 48 53). As we can see from the output, non-ascii keys are not displayed in the upper charlabel because the KeyPress event was not generated. The KeyDown event is still raised, and keyinfolabel displays information about the key. The Keys enumeration can be used to test for specific keys by comparing the key pressed to a specific KeyCode. The Visual Studio. NET documentation has a complete list of the Keys enumerations Mouse Event Handling This section explains how to handle mouse events, such as clicks, presses and moves. Mouse events are generated when the mouse interacts with a control. They can be handled for any GUI control that derives from class System.Windows.Forms.Control. Mouse event information is passed using class MouseEventArgs, and the delegate to create the mouse event handlers is MouseEventHandler. Each mouse event-handling method must take an object and a MouseEventArgs object as arguments. The Click event, which we covered earlier, uses delegate EventHandler and event arguments EventArgs. Class MouseEventArgs contains information about the mouse event, such as the x- and y-coordinates of the mouse pointer, the mouse button pressed, the number of clicks and the number of notches through which the mouse wheel turned. Note that the x- and y-coordinates of the MouseEventArgs object are relative to the control that raised the event.point (0,0) is at the upper-left corner of the control. The various mouse events are described in Fig. 12.29.

Example Code :

On line 14 the program creates variable shouldpaint, which determines whether we should draw on the form. We want to draw only while the mouse button is pressed down. In the event handler for event MouseDown, shouldpaint is set to true (line 27).As soon as the mouse button is released the program stops drawing: shouldpaint is set to false in the MouseUp event handler (line 34). Whenever the mouse moves while the button is pressed down, the MouseMove event is generated. The event will be generated repeatedly, at a rate set by the operating system. Inside the Painter_MouseMove event handler (lines 39 48), the program draws only if shouldpaint is true (indicating that the mouse button is down). Line 44 creates the Graphics object for the form, which provides methods for drawing various shapes. Method FillEllipse (lines 45 47) draws a circle at every point the mouse cursor moves over (while the mouse button is pressed). The first parameter to method FillEllipse is a SolidBrush object, which determines the color of the shape drawn. We create a new SolidBrush object by passing the constructor a Color value. Structure Color contains numerous predefined color constants we selected Color.BlueViolet (line 46). The SolidBrush fills an elliptical region, which lies inside a bounding rectangle. The bounding rectangle is specified by the x- and y-coordinates of its upper-left corner, its height and its width. These four parameters are the final four arguments to method FillEllipse. The x-and y- coordinates are the location of the mouse event: They can be taken from the mouse event arguments (e.x and e.y). To draw a circle, we set the height and width of the bounding rectangle equal in this case, they are each 4 pixels. GOOD LUCK