Windows Forms - Chapter 4 Windows Forms GUI/EDP Concepts...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 4 Windows Forms GUI/EDP
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  Concepts   Windows Forms —for writing GUI based applications (Windows Applications). GUI : Graphical User Interface, to make programs easy to use, WYSIWYG (What you see is what you get). Look => Appearance (Layout Design) Feel => Response (Event Handling) User => Button Click => Event => Event Handler (a method). GUI-based application => Event-driven programming Event-Driven Programming (EDP): Application waits (idles) until the user generates an event trough an input device (keyboard, mouse, …). The OS dispatches the event to the application who owns the window. The corresponding event handler(s) of the application is invoked to process the event.
Background image of page 2
Events A menu in C++: char c; bool done = false; while(!done) { cout << “Please make your selection, q to end:” cin >> c; switch(c) { case “+”: add( ); break; case “-”: sub( ); break; case “q”: done = true; break; } } Event Loop Event Mapping Event Event Handler
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key Components of EDP : (1) Event generators: keyboard, GUI items (buttons, menus, …). (2) Events / Messages (Mouse Click, Key Down, …) (3) Event Loop (an infinite loop constantly waits for events) (4) Event Mapping (dispatch events to corresponding event handlers) (5) Event Handlers (methods for processing the events: OnMouseClick(), …) Key Components
Background image of page 4
Key Components of EDP : (1) Event generators - GUI items are predefined. (2) Events / Messages – common used ones predefined . (3) Event Loop: took care by .NET. (4) Event Mapping: took care by .NET. (5) Event Handlers to be implemented by programmers. Key Components of EDP in .NET
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Implementing Windows Applications using NotePad using System; using System.Windows.Forms; using System.Drawing; class MyForm : Form { MyForm () { Text = "Windows Forms Demo"; } // Window Title Property //The Paint Event Handler protected override void OnPaint (PaintEventArgs e) { e.Graphics.DrawString ("Hello, world", Font, new SolidBrush (Color.Black), ClientRectangle); StringFormat format = new StringFormat (); format.Alignment = StringAlignment.Center; //horizontal format.LineAlignment = StringAlignment.Center;//vertical e.Graphics.DrawString ("Hello, again", Font, new SolidBrush (Color.Black), ClientRectangle, format); } static void Main () { //start the event loop with internal event mapping. Application.Run (new MyForm ()); } }
Background image of page 6
(1) GUI Items (Event Generators) System.Windows.Forms.Form Button, Dialog, …. (2) Events: predefined Windows Messages: e.g. WM_KEYDOWN (3) Event Loop: Built in System.Windows.Forms.Application Class: static Run( ) method starts an application’s event loop. .NET EDP Classes
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(4) Event Mapping: System defined ones have their names fixed: e.g. OnPaint(). Other event handlers need to be added to the handler
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

Windows Forms - Chapter 4 Windows Forms GUI/EDP Concepts...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online