 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.

Slides:



Advertisements
Similar presentations
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Advertisements

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 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
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.
Advanced Object-Oriented Programming Features
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
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.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Getting Started Example ICS2O curriculum
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Visual Basic Chapter 1 Mr. Wangler.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Teacher: Ms. Olifer MICROSOFT VISUAL STUDIO 2010: PROPERTIES OF WINDOWS FORM OBJECT.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
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.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
BIL528 – Bilgisayar Programlama II Introduction 1.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Introduction to Windows Programming
Chapter Two Creating a First Project in Visual Basic.
1 Chapter Nine Using GUI Objects and the Visual Studio IDE.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
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.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Graphical User Interface Components Version 1.1. Obectives Students should understand how to use these basic Form components to create a Graphical User.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
Dive Into® Visual Basic 2010 Express
Computing with C# and the .NET Framework
C# Programming: From Problem Analysis to Program Design
3.01 Apply Controls Associated With Visual Studio Form
Chapter Eleven Handling Events.
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Reference: COS240 Syllabus
Using Procedures and Exception Handling
CS360 Windows Programming
Variables and Arithmetic Operations
C# Programming: From Problem Analysis to Program Design
The University of Texas – Pan American
Chapter 3 – Introduction to C# Programming
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1

 2007 Dr. Natheer Khasawneh. Simple Windows Application In Visual Studio 2005, if you choose –File->New Project –Windows Application The following will be generated for you –Form1.cs –Form1.Designer.cs –Program.cs Lets look at them

 2007 Dr. Natheer Khasawneh.

Program.cs using System; using System.Collections.Generic; using System.Windows.Forms; namespace SimpleApplication { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } What is this?

 2007 Dr. Natheer Khasawneh. Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SimpleApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

 2007 Dr. Natheer Khasawneh. Form1.Designer.cs namespace SimpleApplication { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Text = "Form1"; } #endregion }

 2007 Dr. Natheer Khasawneh. Application Class The System.Windows.Forms.Application class wraps the basic functionality to start a.NET application. This class has methods to start and stop applications and their threads, and to process Windows Messages: –DoEvents() –Exit() –ExitThread() –Run() The class also has events and properties to synchronize execution.

 2007 Dr. Natheer Khasawneh. Application Class Run static method begins running a standard application message loop on the current thread. Below is the overload list:

 2007 Dr. Natheer Khasawneh. Partial Class A partial class, or partial type, is a feature of C# programming languages in which the declaration of a class or a struct or an interface may be split across multiple source-code files. Purpose –Very large classes –Separation of concerns –Multiple developer

 2007 Dr. Natheer Khasawneh. Windows Forms Forms are contained within a namespace called System.Windows.Forms that contains around 200 classes, 100 enumeration, more than 40 delegates, 7 interfaces, and 4 structures. The inheritance lineage is Object -> MarshallByRefObject -> Component-> Control-> ScrollableControl-> Form

 2007 Dr. Natheer Khasawneh. Windows Forms

 2007 Dr. Natheer Khasawneh. Form Form class represents window, provides appropriate services –properties: Size, Location, Controls, ShowInTaskbar –methods: Show, Close, SetDesktopLocation –events: Load, Click, Closing Common to derive from Form to create custom form class MyForm : Form { public MyForm() { this.ShowInTaskbar = false; this.Location = new Point(10, 10); this.Size = new Size(100, 100); } define custom form set properties

 2007 Dr. Natheer Khasawneh. Form border Forms can look like windows, dialogs, or tools –controlled using FormBorderStyle property –set ShowInTaskbar property to false for tool windows –window border styles show the icon from the Icon property

 2007 Dr. Natheer Khasawneh. Form properties Form has many properties –used to customize appearance and behavior public class Form : ContainerControl { public IButtonControl AcceptButton { get; set; } public IButtonControl CancelButton { get; set; } public bool HelpButton { get; set; } public Icon Icon { get; set; } public String Text { get; set; } public Size MaximumSize { get; set; } public Size MinimumSize { get; set; } public MainMenu Menu { get; set; } public bool ShowInTaskbar { get; set; } public FormBorderStyle FormBorderStyle { get; set; }... } properties

 2007 Dr. Natheer Khasawneh. SimpleForm.cs using System; using System.Windows.Forms; class SimpleForm { static void Main() { Form f1 = new Form(); f1.Text = "My Simple Form"; Application.Run(f1); } csc /t:winexe SimpleForm.cs

 2007 Dr. Natheer Khasawneh. SimpleForm2.cs using System; using System.Windows.Forms; class SimpleForm { static void Main() { Form f1 = new Form(); f1.Text = "My Simple Form2"; f1.Show(); } What is the output?

 2007 Dr. Natheer Khasawneh. SimpleForm3.cs using System.Threading; using System.Windows.Forms; class SimpleForm { static void Main() { Form f1 = new Form(); f1.Text = "My Simple Form3"; f1.Show(); f1.Text = "Time to sleep"; //Let the process go to sleep for 1000 ms (pause) Thread.Sleep(3000); f1.Text = "Time to wake up !"; //Let the process go to sleep for 1000 ms (pause) Thread.Sleep(1000); } What is the output?

 2007 Dr. Natheer Khasawneh. SimpleForm4.cs using System.Threading; using System.Windows.Forms; class SimpleForm { public static void Main() { Form f1 = new Form(); f1.Text = "What is wrong with this?"; f1.Visible = true; Thread.Sleep(3000); f1.Visible = false; Thread.Sleep(3000); f1.Text = "Coming back to live"; f1.Visible = true; Thread.Sleep(3000); Application.Run(); f1.Text = "After Application.Run is called"; } What is the output?

 2007 Dr. Natheer Khasawneh. SimpleForm5.cs using System.Threading; using System.Windows.Forms; class SimpleForm { public static void Main() { Form f1 = new Form(); f1.Text = "What is wrong with this?"; f1.Visible = true; Thread.Sleep(3000); f1.Visible = false; Thread.Sleep(3000); f1.Text = "Coming back to live"; f1.Visible = true; Thread.Sleep(3000); Application.Run(f1); Thread.Sleep(3000); f1.Text = "After Application.Run is called"; } What is the output?

 2007 Dr. Natheer Khasawneh. SimpleForm6.cs using System.Threading; using System.Windows.Forms; class SimpleForm { public static void Main() { Form f1 = new Form(); f1.Text = "How are you all doing?"; f1.Visible = true; Thread.Sleep(3000); f1.Text = "And How is your Baba?"; Application.Run(f1); Thread.Sleep(3000); f1.Text = "After Application.Run is called"; MessageBox.Show("And your Daddy too?"); } What is the output?

 2007 Dr. Natheer Khasawneh. Conclusion Main creates the form and displays it. The form is given to Application.Run where it continues to exist. The form takes control of execution until the form is dismissed. When the form is dismissed, presumably, the Application.Run method continues (err, ends). The Application.Run method returns control to Main, which then calls the MessageBox.Show method. The application ends after the MessageBox is dismissed

 2007 Dr. Natheer Khasawneh. SimpleForm7.cs using System.Threading; using System.Windows.Forms; class SimpleForm { public static void Main() { Form f0 = new Form(); f0.Text = "How are you?"; Form f1 = new Form(); f1.Text = "How is C#?"; Form f2 = new Form(); f2.Text = "How is C++"; f0.Show(); f2.Show(); Application.Run(f1); MessageBox.Show("Where are we?"); f2.Text = "F2, after Application.Run is called"; Thread.Sleep(3000); } Take Home Bring back your description Quiz

 2007 Dr. Natheer Khasawneh. Not Very Simple Windows Application! Drag and drop textbox and button from the toolbox into the Form Lets see what happened to our three files. Program.cs Form1.cs Form1.Designer.cs

 2007 Dr. Natheer Khasawneh. Program.cs using System; using System.Collections.Generic; using System.Windows.Forms; namespace SimpleApplication { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } NO CHANGES!

 2007 Dr. Natheer Khasawneh. Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SimpleApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); } NO CHANGES!

 2007 Dr. Natheer Khasawneh. Form1.Designer.cs namespace SimpleApplication { partial class Form1 { //SAME AS BEFORE CODE OMMITED FOR SPACE private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // textBox1 this.textBox1.Location = new System.Drawing.Point(72, 24); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(100, 20); this.textBox1.TabIndex = 0; // button1 this.button1.Location = new System.Drawing.Point(82, 59); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; // Form1 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(246, 109); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout();} #endregion } We have two new fields The fields properties are initialized The fields are attached to the Form

 2007 Dr. Natheer Khasawneh. Not Simple Windows Application! Lets say I want to find the square of the number entered Double click on the button, and suddenly Form1.cs is opened for me and the following code is displayed for me.

 2007 Dr. Natheer Khasawneh. Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SimpleApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int x = int.Parse(textBox1.Text); x = x*x; MessageBox.Show(x.ToString()); } This method is written for me I wrote this code

 2007 Dr. Natheer Khasawneh. Form1.Designer.cs namespace SimpleApplication { partial class Form1 { //SAME AS BEFORE CODE OMMITED FOR SPACE //THE BUTTON1 IS THE PART THAT CHANGES // button1 // this.button1.Location = new System.Drawing.Point(82, 59); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); } control Event Event handler (method name)

 2007 Dr. Natheer Khasawneh. class MyForm : Form { Button button1 = new Button(); Label label1 = new Label (); public MyForm() {... this.Controls.Add(button1); this.Controls.Add(label1 ); }... } myForm Form as container Form manages a list of controls –stored in Controls collection property Controls button1label1 all forms inherit Controls collection add to collection

 2007 Dr. Natheer Khasawneh. What We Just Did? We have attached an event handler for the click event. Button has Click event If this event happens (some one clicks on the button) button1_Click method will be executed.

 2007 Dr. Natheer Khasawneh. SimpleForm8.cs I like this code.. using System; using System.Threading; using System.Windows.Forms; class SimpleForm { public static void Main() { MyForm f1 = new MyForm(); Application.Run(f1); } class MyForm : Form { private TextBox textBox1; private Button button1; public MyForm() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.textBox1.Location = new System.Drawing.Point(72, 24); this.textBox1.Name = "textBox1"; this.button1.Location = new System.Drawing.Point(82, 59); this.button1.Name = "button1"; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; } private void button1_Click(object sender, EventArgs e) { int x = int.Parse(textBox1.Text); x = x * x; MessageBox.Show(x.ToString()); }