Download presentation
Presentation is loading. Please wait.
Published byBonnie Boyd Modified over 9 years ago
1
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling
2
I NTRODUCTION 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
3
I NTRODUCTION 3 Sample Internet Explorer window with GUI components. ButtonLabelMenu Bar TextBoxScrollbar
4
I NTRODUCTION 4 What are these?
5
W INDOWS F ORMS 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
6
W INDOWS F ORMS 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
7
D ESIGN P ROCESS For creating Windows Applications Create a windows form Set its properties Add controls Set their properties Implement event handlers 7
8
W INDOWS F ORMS 8
9
E VENT -H ANDLING M ODEL 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
10
E VENT -H ANDLING M ODEL 10 Event-handling model using delegates. Object A raises event EDelegate for event E Handler 1 for event E Handler 3 for event E Handler 2 for event E calls Intermediary for object and methods
11
B ASIC E VENT H ANDLING 11 Events section of the Properties window. DEMO! Current event handler Selected event Event description List of events supported by control Events icon
12
12 //SimpleEventExample.cs using 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 handler Reference 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)
13
13 P ROGRAM O UTPUT
14
B ASIC E VENT H ANDLING 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
15
B ASIC E VENT H ANDLING Event multicasting Have multiple handlers for one event Order called for event handlers is indeterminate 15
16
16 List of Form events. Class name List of events web page link
17
17 Details of Click event. Event delegate Event argument class Event name
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.