g raphical u ser i nterface c oncepts : p art 1 1 outline introduction windows forms event-handling...
TRANSCRIPT
![Page 1: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/1.jpg)
GRAPHICAL USER INTERFACE CONCEPTS: PART 1
1
OutlineIntroductionWindows FormsEvent-Handling Model
- Basic Event Handling
![Page 2: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/2.jpg)
INTRODUCTION
Graphical user interface Is an object that allows user to interact with
program visually using keyboard or mouse Built from window gadgets aka widgets (controls) Give program distinct look and feel
Consistency enables users to learn new apps faster
2
![Page 3: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/3.jpg)
INTRODUCTION
3
Sample Internet Explorer window with GUI components.
Button Label Menu Bar TextBox Scrollbar
![Page 4: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/4.jpg)
INTRODUCTION
4
Control Label
TextBox
Button
CheckBox
ComboBox
ListBox
Panel
ScrollBar
What are these?
![Page 5: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/5.jpg)
WINDOWS FORMS
Forms Create GUIs for programs Graphical element on the desktop Represented by:
Dialog Window Multiple document interface (MDI) window
Acts as a container for components and controls
5
![Page 6: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/6.jpg)
WINDOWS FORMS Control
Visible component with graphical part Such as button or label
Component Class that implements IComponent interface
(defines behaviors components must implement) Lacks visual parts
Such as Timer or DirectorySearcher
Event Generated by movement from mouse or keyboard Event handlers performs action
Specifics written by programmer
6
![Page 7: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/7.jpg)
DESIGN PROCESS
For creating Windows Applications Create a windows form Set its properties Add controls Set their properties Implement event handlers
7
![Page 8: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/8.jpg)
WINDOWS FORMS
8
Form Properties and Events
Description / Delegate and Event Arguments
Common Properties
AcceptButton Which button will be clicked when Enter is pressed.
AutoScroll Whether scrollbars appear when needed (if data fills more than one screen).
CancelButton Button that is clicked when the Escape key is pressed.
FormBorderStyle Border of the form (e.g., none, single, 3D, sizable).
Font Font of text displayed on the form, as well as the default font of controls added to the form.
Text Text in the form’s title bar.
Common Methods
Close Closes form and releases all resources. A closed form cannot be reopened.
Hide Hides form (does not release resources).
Show Displays a hidden form.
Common Events (Delegate EventHandler, event arguments EventArgs)
Load Occurs before a form is shown. This event is the default when the form is double-clicked in the Visual Studio .NET designer.
Common Form properties and events.
![Page 9: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/9.jpg)
EVENT-HANDLING MODEL GUIs are event driven
User moves or clicks mouse, clicks a button, types in a textbox, selects from a menu or listbox, closes a window
Event handlers Methods that process events and perform tasks.
Each control that can generate events has an associated delegate Object that reference methods Defines the signature for control’s event handler Event delegates are multicast
Contain lists of method references (every one is called) Each must have same signature
9
![Page 10: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/10.jpg)
EVENT-HANDLING MODEL
10Event-handling model using delegates.
Object A raises event E Delegate for event E
Handler 1 for event E
Handler 3 for event E
Handler 2 for event E
calls
calls
Intermediary for object and methods
![Page 11: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/11.jpg)
BASIC EVENT HANDLING
11
Events section of the Properties window. DEMO!
Current event handler
Selected event
Event description
List of events supported by control
Events icon
![Page 12: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/12.jpg)
12
//SimpleEventExample.csusing System;using System.Windows.Forms;
namespace SimpleEventExample2{ //program that shows a simple event handler
public partial class MyForm : Form { public MyForm() { InitializeComponent(); }
// Visual Studio .NET creates an empty handler, // we write definition: show message box when form clicked private void MyForm_Click( object sender, System.EventArgs e ) { MessageBox.Show( "Form was clicked" ); } } //end class MyForm}
Create an event handler
Signature of the event handlerReference to the object that raised the event (sender)
Class EventArgs is base class for objects with event information
Reference to an event arguments object (e)
![Page 13: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/13.jpg)
13
PROGRAM OUTPUT
![Page 14: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/14.jpg)
BASIC EVENT HANDLING Event handler
ControlName_EventName MyForm_Click Two object references are passed in (sender and e) Must have same signature as corresponding delegate
Clicking name of event brings up its delegate Must be registered with delegate object
Add event handlers to the delegate’s invocation list Visual Studio.NET does this for us
Controls have a delegate reference for each event New delegate object for each event handler
this.Click += new System.EventHandler
(this.MyForm_Click); 14
![Page 15: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/15.jpg)
BASIC EVENT HANDLING
Event multicasting Have multiple handlers for one event Order called for event handlers is indeterminate
15
![Page 16: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/16.jpg)
16
List of Form events.
Class name
List of events
web page link
![Page 17: G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling](https://reader030.vdocument.in/reader030/viewer/2022032607/56649ec05503460f94bcbfd7/html5/thumbnails/17.jpg)
17
Details of Click event.
Event delegateEvent argument class
Event name