COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Chapter 1: An Introduction to Visual Basic 2012
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Programming Based on Events
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.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Chapter 2 –Visual Basic, Controls, and Events
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Chapter 8: Writing Graphical User Interfaces
IE 411/511: Visual Programming for Industrial Applications
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Lecture Set 3 Introduction to Visual Basic Concepts Part C – Design Mode Properties In-Depth Look at Common Features of Controls.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
BIL528 – Bilgisayar Programlama II Introduction 1.
Introduction to Windows Programming
Chapter Two Creating a First Project in Visual Basic.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2: The Visual Studio .NET Development Environment
INF230 Basics in C# Programming
Computing with C# and the .NET Framework
C# Programming: From Problem Analysis to Program Design
Chapter 1: An Introduction to Visual Basic 2015
C# & Windows GUI Applications
Chapter 2 – Introduction to the Visual Studio .NET IDE
Reference: COS240 Syllabus
Windows Desktop Applications
C# Programming: From Problem Analysis to Program Design
CIS16 Application Development Programming with Visual Basic
Presentation transcript:

COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus

Lecture Contents: Contrast btw the functions of Windows applications and console applications GUI - graphical user interfaces Windows forms and form properties Control objects such as buttons, labels, and text boxes to a form

Contrasting Windows and Console Applications Console applications –Each line in Main( ) method executed sequentially – then the program halts –Method calls might branch to different locations in the program, however control always returns back to Main –Program initiates interaction with the user by calling the OS to get data using ReadLine() method –Program calls OS to output data through method calls like WriteLine() or Write() Console applications run IPO model of computing process

Contrasting Windows and Console Applications Windows applications –Instead of the program executing sequential statements from top to bottom, the application, once launched, sits in what is called a process loop and waits for an event –Sits in a process loop, waiting for event to execute Windows applications run Event-driven model of a computing process

Contrasting Windows and Console Applications Event: notification from OS that an action, such as the user clicking the mouse or the user pressing a key, has occurred Instead of calling the OS with IO request as console applications, Windows applications receive messages from OS that event has occurred It is must to write methods, called Event Handlers to indicate what should be done when an event occurs

Graphical User Interface Windows applications also look different from console applications User Interface: front end of a program –Visual image you see when you run a program –Algorithmic functionality stays behind GUI –Often users of programs actually identify the interface of the program itself, when in reality, the interface is just one facet of the program. –Algorithmic complexity is hidden behind GUI.

Graphical User Interface Graphical user interface (GUI) includes: –Menus, labels, text boxes, list boxes, –Other controls (pictures, buttons, etc.) –Text in many different colors and sizes Controls are objects that can display and respond to user interaction. Controls are placed in a container, called form, which is an object as well. It is instance of a class derived from predefined class Form

Windows Based Applications Windows Forms Events Controls

Chapter 9 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 4th Edition

C# Programming: From Problem Analysis to Program Design10 Contrasting Windows and Console Applications Windows applications function differently from console applications. Windows applications look differently from console applications.

C# Programming: From Problem Analysis to Program Design11 Contrasting Windows and Console Applications by Functionality Console applications –Each line in Main( ) executed sequentially – then the program halts Windows applications –Once launched, sits and waits for an event –Sits in a process loop Event: notification from operating system that an action, such as the user clicking the mouse or pressing a key, has occurred –Write event-handler methods for Windows apps

C# Programming: From Problem Analysis to Program Design12 Graphical User Interfaces Windows applications also look different from console applications Interface: front end of a program –Visual image you see when you run a program Graphical user interface (GUI) includes: –Menus –Text in many different colors and sizes –Other controls (pictures, buttons, etc.)

C# Programming: From Problem Analysis to Program Design13 Windows Applications Reference and import System.Windows.Forms namespace Class heading definition –Includes not only the class name, but a colon followed by another class name Derived class (first class), Base class (second class) public class Form1 : Form Derived classes inherit from base class No multiple inheritance within.NET languages

C# Programming: From Problem Analysis to Program Design14 Windows Applications ( continued ) Text - property of the Form class –A property for setting/getting title bar caption –Can be used in constructor Windows forms/controls offer many properties including Text, Color, Font, and Location Execution begins in Main( ) method –Main( ) is located in Program.cs file for the application –Call to Run( ) method places application in process loop

C# Programming: From Problem Analysis to Program Design15 // Windows0.cs Author: Doyle using System.Windows.Forms; // Line 1 namespace Windows0 { public class Form1 : Form // Line 2 { public Form1( ) // Line 3 { Text = "Simple Windows Application"; // Line 4 } static void Main( ) { Form1 winForm = new Form1( ); // Line 5 Application.Run(winForm); // Line 6 } New namespace referenced Constructor Base class Sets title bar caption Starts process loop

C# Programming: From Problem Analysis to Program Design16 Windows Application ( continued ) Figure 9-1 Windows-based form Output generated from Windows0 application

C# Programming: From Problem Analysis to Program Design17 Elements of Good Design Appearance matters –Human-computer interaction (HCI) research Design considerations –Consistency –Alignment –Avoid clutter –Color –Target audience

C# Programming: From Problem Analysis to Program Design18 Use Visual Studio to Create Windows-Based Applications Windows Forms Application template Browse to location to store your work Name Figure 9-2 Visual Studio New Windows application Select File New Project

C# Programming: From Problem Analysis to Program Design19 Windows-Based Applications Properties Window Toolbox Figure 9-3 Initial design screen Design View

C# Programming: From Problem Analysis to Program Design20 Windows-Based Applications ( continued ) Figure 9-4 Dockable windows

Windows Based Applications Windows Forms –Properties –Events

C# Programming: From Problem Analysis to Program Design22 Windows Forms Extensive collection of Control classes Top-level window for an application is called a Form Each control has collection of properties and methods –Select property from an alphabetized list (Properties window) –Change property by clicking in the box and selecting or typing the new entry at design time. Each control has collection of events.

C# Programming: From Problem Analysis to Program Design23 Windows Form Properties Properties Figure 9-5 Properties window Property value

Windows Form Properties (change values at run time) Can set properties using program statements –Table 9-1 shows properties set using Properties window Selecting Code on View menu shows associated code C# Programming: From Problem Analysis to Program Design24 Table 9-1 Form1 property changes

Windows Form Events C# Programming: From Problem Analysis to Program Design25 Figure 9-6 Form events

Inspecting the Code Generated by Visual Studio Three source code files ending with a.cs extension are part of the application C# Programming: From Problem Analysis to Program Design26 Figure 9-7 Solution Explorer window Expand Form1.cs node to reveal the Form1.Designer.cs file

C# Programming: From Problem Analysis to Program Design27 Simple Windows Application IDE separates the source code into three separate files –Form1.cs: normally this is the only one you edit –Form1.Designer.cs: holds the auto generated code –Program.cs: contains the Main( ) method, where execution always begins Form1.cs and Form1.Designer.cs both include partial class definitions for the Form1 class

Inspecting the Code - Form1.cs Number of namespaces automatically added, including System.Windows.Forms Constructor calls InitializeComponent( ) method public Form1( ) { // Required for Windows Form Designer support. InitializeComponent( ); } This is the file where event handler methods will be placed C# Programming: From Problem Analysis to Program Design28

Inspecting the Code - Form1.Designer.cs InitializeComponent( ) method included here #region Windows Form Designer generated code preprocessor directive –// do not modify the contents of this method with the Code Editor –Keyword “this.” precedes property name Refers to current instance of the class –#endregion // Ends the preprocessor directive C# Programming: From Problem Analysis to Program Design29

InitializeComponent( ) Method BackColor = Color.FromArgb (((Byte)(255)), ((Byte)(224)), ((Byte)(192))); ClientSize = new Size(392, 373); Font = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Point, ((Byte)(0))); ForeColor = Color.Blue; Location = new Point(30, 30); Margin = new Padding(4); MaximizeBox = false; Name = "Form1"; StartPosition = FormStartPosition.CenterScreen; Text = "First Windows Application"; Some of the auto generated code in the method –Added as default values for properties or from changing property values C# Programming: From Problem Analysis to Program Design30

Windows Based Applications Events

C# Programming: From Problem Analysis to Program Design32 Windows Form Events Add code to respond to events, like button clicks –Code goes into Form1.cs file From the Properties window, select the lightning bolt (Events) –Double-click on the event name to generate code Registers the event as being of interest Adds a heading for event-handler method

C# Programming: From Problem Analysis to Program Design33 Windows Form Properties ( continued ) Events button selected Figure 9-6 Form1 events

C# Programming: From Problem Analysis to Program Design34 Windows Form – Load Event Code automatically added to register event Code automatically added for method heading private void Form1_Load(object sender, EventArgs e) { } You add statement to event-handler method body this.BackColor = Color.Azure;

C# Programming: From Problem Analysis to Program Design35 Windows Form – FormClosing Event Code automatically added to register event Code automatically added for method heading private void Form1_FormClosing(object sender, FormClosingEventArgs e) { } You add statement to event-handler method body MessageBox.Show("Hope you are having fun!");

Running the Windows Application No changes needed in the file that has Main( ) Run like you do console applications (F5 or Ctrl+F5) C# Programming: From Problem Analysis to Program Design36 Figure 9-8 Output produced when the Close button causes the event-handler method to fire Review FirstWindows Example

Windows Based Applications Controls

C# Programming: From Problem Analysis to Program Design38 Controls Controls are all classes –Button, Label, TextBox, ComboBox, MainMenu, ListBox, CheckBox, RadioButton, and MonthCalendar Each comes with its own predefined properties and methods Each fires events Each is derived from the System.Windows.Forms.Control class

C# Programming: From Problem Analysis to Program Design39 Controls ( continued ) Dots indicate other classes are derived from the class Figure 9-9 Control class hierarchy

C# Programming: From Problem Analysis to Program Design40 Standard Controls Figure 9-10 Windows Forms controls

C# Programming: From Problem Analysis to Program Design41 Controls ( continued ) Two procedures to place controls –From Toolbox, double-click on control or drag and drop Move, resize, and delete controls Format controls –Align controls –Make same size –Horizontal and vertical spacing

C# Programming: From Problem Analysis to Program Design42 Properties of the Control class Table 9-2 Systems.Windows.Forms.Control class properties

Properties of the Control class ( continued ) C# Programming: From Problem Analysis to Program Design43 Table 9-2 Systems.Windows.Forms.Control properties ( continued )

Methods of the Control class Control class has over 75 properties and over 100 methods –Not all are useful for every class that derives from it C# Programming: From Problem Analysis to Program Design44 Table 9-3 Systems.Windows.Forms.Control methods Table 9-3 includes a short list of some of the many methods. Explore MSDN documentation for more

C# Programming: From Problem Analysis to Program Design45 Controls ( continued ) Figure 9-11 GUI controls

Practical Tasks Write a Windows based application – pure empty form with no any user added forms, controls or events

Practical Tasks Write a Windows based application – pure empty form with modified Text property at design time using Properties window

Practical Tasks Write a Windows based application – pure empty form with two event handlers: Event Load – when the form gets loaded –To modify Text property and BackColor property at run time Event FormClosing – when the form gets closed – prior to app termination –Call Message.Show() method

Thank You For Your Attention