1 / 17

Graphical User Interface Concepts: Part 1

Graphical User Interface Concepts: Part 1. Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling. Introduction. Graphical user interface Is an object that allows user to interact with program visually using keyboard or mouse

kelvin
Download Presentation

Graphical User Interface Concepts: Part 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphical User Interface Concepts: Part 1 OutlineIntroductionWindows FormsEvent-Handling Model - Basic Event Handling

  2. 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

  3. Introduction Button Label Menu Bar TextBox Scrollbar Sample Internet Explorer window with GUI components.

  4. Introduction What are these?

  5. Windows Forms • WinForms • Create GUIs for programs • Graphical element on the desktop • Represented by: • Dialog • Window • Multiple document interface (MDI) window • Acts as a container form components and controls

  6. 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

  7. Design Process • For creating Windows Applications • Create a windows form • Set its properties • Add controls • Set their properties • Implement event handlers

  8. Windows Forms

  9. 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

  10. calls Handler 1 for event E calls Object A raises event E Delegate for event E Handler 2 for event E Handler 3 for event E Event-Handling Model • Intermediary for object and methods Event-handling model using delegates.

  11. Basic Event Handling Events icon List of events supported by control Current even handler (none) Selected event Event description Events section of the Properties window. DEMO!

  12. //SimpleEventExample.cs using System; usingSystem.Windows.Forms; namespace SimpleEventExample2 { //program that shows a simple event handler publicpartialclassMyForm : Form { publicMyForm() { InitializeComponent(); } // Visual Studio .NET creates an empty handler, // we write definition: show message box when form clicked privatevoidMyForm_Click( object sender, System.EventArgs e ) { MessageBox.Show( "Form was pressed" ); } } //end class MyForm } Create an event handler Class EventArgs is base class for objects with event information Reference to the object that raised the event (sender) Signature of the event handler Reference to an event arguments object (e)

  13. Program Output

  14. 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);

  15. Basic Event Handling • Event multicasting • Have multiple handlers for one event • Order called for event handlers is indeterminate

  16. List of events Class name List of Form events.

  17. Event name Event delegate Event argument class Details of Click event.

More Related