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.
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
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
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.
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 2005 CHAPTER 8 Using Procedures and Exception Handling.
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.
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.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
BIL528 – Bilgisayar Programlama II Introduction 1.
Introduction to Windows Programming
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.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
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.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008.
Dive Into® Visual Basic 2010 Express
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 1: An Introduction to Visual Basic .NET
Java FX: Scene Builder.
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
IS 350 Course Introduction
C# & Windows GUI Applications
Looking at our “Getting Started” application
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
Program and Graphical User Interface Design
1. Introduction to Visual Basic
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Windows Desktop Applications
Program and Graphical User Interface Design
C# Programming: From Problem Analysis to Program Design
Social Media And Global Computing Introduction to Visual Studio
Chapter 2 – Introduction to the Visual Studio .NET IDE
CIS16 Application Development Programming with Visual Basic
6. WinForms 2003 C# GUI - Basics.
Introduction to Programming
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Reference: COS240 Syllabus 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 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

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 Design

Contrasting Windows and Console Applications by Functionality 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 Design

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 Design

Windows Applications public class Form1 : Form 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 Design

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 Design

New namespace referenced // 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 Base class Constructor Sets title bar caption Starts process loop C# Programming: From Problem Analysis to Program Design

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

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 Design

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

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

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

Windows Based Applications Windows Forms Properties Events

Windows Forms Each control has collection of events. 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 Design

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

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 Table 9-1 Form1 property changes C# Programming: From Problem Analysis to Program Design

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

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

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 C# Programming: From Problem Analysis to Program Design

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 Design

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 Design

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 Design

Windows Based Applications Events

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 Design

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

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 Design

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!"); C# Programming: From Problem Analysis to Program Design

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

Windows Based Applications Controls

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 Design

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

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

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 Design

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

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

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 Table 9-3 includes a short list of some of the many methods. Explore MSDN documentation for more Table 9-3 Systems.Windows.Forms.Control methods C# Programming: From Problem Analysis to Program Design

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

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