 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:

Slides:



Advertisements
Similar presentations
CSCI 3328 Object Oriented Programming in C# Chapter 10: Graphical User Interfaces with Windows Forms 1 Xiang Lian The University of Texas – Pan American.
Advertisements

Nov 2005 MSc Slide 1 - Another Example of a Structural Pattern Alternative way of adding Functionality to an existing class (alternative to a derived class)
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
Pemrograman VisualMinggu …8… Page 1 MINGGU Ke Delapan Pemrograman Visual Pokok Bahasan: Graphical User Interface Tujuan Instruksional Khusus: Mahasiswa.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control.
Event Handling Events and Listeners Timers and Animation.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
 2007 Dr. Natheer Khasawneh 1 Chapter 13. Graphical User Interface Concepts: Part 1 Continue from previouse lecture.
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
Mouse draw Using the mouse and a palette to make a picture.
Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
 2006 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part I.
MsgBox Function Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon After displaying.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Software Engineering1 The.NET Framework and the CLI 2D Graphics with GDI+ Visual Studio.NET 2008.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
CSCI 3327 Visual Basic Chapter 10: Windows Forms GUI: A Deeper Look UTPA – Fall 2011.
Object Oriented Programming Graphical User Interfaces Dr. Mike Spann
Lecture 4 Advanced Topics Devi, Erick, Reddy. » Declare dynamic component, an example: ˃Create a button Button newBtn = new Button(); ˃Create an array.
CSC 298 Windows Forms.
BIM211 – Visual Programming Objects, Collections, and Events 1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
Carnegie Mellon University MSCF1 C#/.NET Basics 2 Some code is from “C# in a Nutshell”
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
 2002 Prentice Hall. All rights reserved. 1 Outline 12.1 Introduction 12.2 Windows Forms 12.3 Event-Handling Model Basic Event Handling 12.4 Control.
Visual C# 2012 How to Program 1. 2  A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual.
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Events with Data Arguments Data Values Travel with e.
COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling.
BIM211 – Visual Programming Interacting with Users Graphics 1.
Omer Boyaci.  GUIs are event driven.  When the user interacts with a GUI component, the interaction—known as an event—drives the program to perform.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
C # Graphical User Interfaces BIT-6 Saad Liaquat.
Events with Data Arguments Data Values Travel with e.
Events Programming in C# Events CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Host Objects: Browsers and the DOM
CISC 110 Day 6 Introduction to Events. Outline Event-Driven Programming Event Classes Hierarchy –Event Class –Mouse Events –Keyboard Events Registering.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
Week 7: Debugging and Error Handling Debugging methods available in the ID Error-handling techniques available in C#
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
Dr. Abraham Professor UTPA Graphical User Interface.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
 2007 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part 1.
CHAPTER 8 TAMING THE MOUSE
Object Oriented Programming
Keyboards, Pages & Transforms
Chapter Eleven Handling Events.
Chapter 5: Programming with C#
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Chapter 12 - Graphical User Interface Concepts: Part 1
Visual Basic Properties, Methods and Events
CSE 154 Lecture 11: More Events.
Visual programming Chapter 4: GUI (Graphical User Interface) Part II
Chapter 13: Handling Events
The Keyboard Jim Fawcett
CHAPTER 8 TAMING THE MOUSE
Presentation transcript:

 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:

 2002 Prentice Hall. All rights reserved. 2 Mouse Event Handling Mouse events generated when mouse interacts with a control Mouse event-handling methods take an object and a MouseEventArgs object as arguments Class MouseEventArgs –Contain coordinates of the mouse pointer relative to control –Mouse button pressed –Number of clicks and number of notches the wheel turned –Passing mouse event –The Click event uses delegate EventHandler and event arguments EventArgs

 2002 Prentice Hall. All rights reserved. 3 Properties and Events Properties –Button –Clicks –X –Y Events (all relative to the control) –MouseEnter (enters control) –MouseLeave –MouseDown –MouseHover –MouseMove –MouseUp

 2002 Prentice Hall. All rights reserved. Outline 4 // Using the mouse to draw on a form. // creates a form as a drawing surface public partial class PainterForm : Form { bool shouldPaint = false; // whether to paint //paint after mouse button has been pressed private void PainterForm_MouseDown ( object sender, System.Windows.Forms.MouseEventArgs e ) { shouldPaint = true; } // stop painting when mouse button released private void PainterForm_MouseUp ( object sender, System.Windows.Forms.MouseEventArgs e ) { shouldPaint = false; } Creates variable shouldPaint to determine whether to draw on the form The event handler for event MouseDown shouldPaint is set to true when this event occurs Mouse cursor will draw The event handler of event MouseUp shouldPaint set to false, mouse cursor will not draw

 2002 Prentice Hall. All rights reserved. Outline 5 // draw circle whenever mouse button // moves (and mouse is down) protected void PainterForm_MouseMove( object sender, System.Windows.Forms.MouseEventArgs e ) { if ( shouldPaint ) { Graphics graphics = CreateGraphics(); graphics.FillEllipse( new SolidBrush( Color.BlueViolet ), e.X, e.Y, 4, 4 ); } } // end Painter_MouseMove Program will draw only if shouldPaint is true Creates the graphic object for the form Provides method for drawing various shapes Method FillEllipse draws a circle at every point the mouse cursor moves over and shouldPaint is true SolidBrush object determines the color of the shape drawn Create new SolidBrush object by passing the constructor a Color value Structure Color contain numerous predefined color constants Coordinates of x and y and the pixels height and width are supplied to the parameter list DEMO Painter

 2002 Prentice Hall. All rights reserved. 6 Keyboard Event Handling Key events –Any control that inherits from System.Windows.Forms.Control Two Types 1.Delegate KeyPressEventHandler –Event argument KeyPressEventArgs –KeyPress ASCII character pressed No modifier keys 2.Delegate KeyEventHandler –Event argument KeyEventArgs –KeyUp or KeyDown Special modifier keys –Key enumeration value

 2002 Prentice Hall. All rights reserved. 7 KeyPressEventHandler Properties and Events Properties –KeyChar (ascii) –Handled (whether key press event was handled) Events –KeyPress

 2002 Prentice Hall. All rights reserved. 8 KeyEventHandler Properties and Events Properties –Alt, Contrl, Shift – whethere they were pressed –Handled –KeyData (returns as a Keys enumeration) –KeyValue (returns as an int) –Modifiers (returns a Key enum for any modifier key) Events –KeyDown (when initially pushed down) –KeyUp(when released)

 2002 Prentice Hall. All rights reserved. Outline 9 // Displays info about the key pressed. public partial class KeyDemoForm :Form { private System.Windows.Forms.Label charLabel ; private System.Windows.Forms.Label keyInfoLabel ; private System.ComponentModel.Container components = null; // display the character pressed using key char protected void KeyDemoForm_KeyPress( object sender, System.Windows.Forms.KeyPressEventArgs e ) { charLabel.Text = "Key pressed: " + e.KeyChar; } Forms contain two LabelsLabel for key pressedLabel for modifier informationInitially emptyKeyPress event handler Accesses the KeyChar property of the KeyPressEventArgs object Key pressed as a char Display the key pressed If key pressed is not ASCII, charLabel remains empty

 2002 Prentice Hall. All rights reserved. Outline 10 // display modifier keys, key code, key data and key value private void KeyDemoForm_KeyDown( object sender, System.Windows.Forms. KeyEventArgs e ) { keyInfoLabel.Text = "Alt: " + ( e.Alt ? "Yes" : "No") + '\n' + "Shift: " + ( e.Shift ? "Yes" : "No" ) + '\n'+ "Ctrl: " + ( e.Control ? "Yes" : "No" ) + '\n' + " KeyCode: " + e.KeyCode + '\n' + "KeyData: " + e.KeyData + '\n' + "KeyValue: " + e.KeyValue; } // clear labels when key released private void KeyDemoForm_KeyUp ( object sender, System.Windows.Forms. KeyEventArgs e ) { keyInfoLabel.Text = ""; charLabel.Text = ""; } KeyEventArgs object This block test for special keys, return bool if matched Uses Alt, Shift, and Control properties Displays the KeyCode, KeyData, and KeyValue properties KeyCode returns a Keys enumeration converted into a string using ToString KeyCode returns the key pressed without modifier keys information KeyData property returns a Keys enumeration with data about modifier keys KeyValue returns the key code as an integerInteger value is the Windows virtual key code KeyUp event handler clears both labels

 2002 Prentice Hall. All rights reserved. Outline 11 KeyDemo.cs Program Output KeyPress event was not engagedKeyDown event still raised so keyInfoLabel displays information Keys enumeration can test for specific keys by comparing key pressed to KeyCode