6. WinForms: GUI Programming in.NET. 2 Microsoft Objectives.NET supports two types of form-based apps, WinForms and WebForms. WinForms are the traditional,

Slides:



Advertisements
Similar presentations
Module 1: BLOCK 1 / MAIN MENU
Advertisements

Getting Started with Microsoft Office 2007
Chapter 16 Graphical User Interfaces
Creating Applications With Visual Basic
Multiple Forms, Standard Modules, And Menus
BASIC SKILLS AND TOOLS USING ACCESS
XP New Perspectives on Microsoft Office Word 2003 Tutorial 7 1 Microsoft Office Word 2003 Tutorial 7 – Collaborating With Others and Creating Web Pages.
Microsoft Access 2007 Advanced Level. © Cheltenham Courseware Pty. Ltd. Slide No 2 Forms Customisation.
Create an Application Title 1A - Adult Chapter 3.
Mike Scott University of Texas at Austin
Microsoft®.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Windows XP Project An Introduction to Microsoft Windows XP and Office 2003.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Key Applications Module Lesson 11 — Using Microsoft Office 2003
1 Northwind Traders Order Entry. 2 Northwind Traders Call Center Add an Order Entry capability to the Northwind Traders Call Center application. Start.
Microsoft Access.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
INTRODUCTION Lesson 1 – Microsoft Word Word Basics
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Office 2003 Integration Integrating Office 2003 Applications and the World Wide Web.
Microsoft Office Word is an example of ____ software. a. Database b
Chapter 11: The X Window System Guide To UNIX Using Linux Third Edition.
Benchmark Series Microsoft Excel 2013 Level 2
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Collin College Credit Exam
Pasewark & Pasewark Microsoft Office XP: Introductory Course 1 INTRODUCTORY MICROSOFT WORD Lesson 8 – Increasing Efficiency Using Word.
Benchmark Series Microsoft Excel 2010 Level 1
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 2Advanced Reports, Access Tools, and Customizing Access Chapter 8Integrating Access Data.
Import Tracking and Landed Cost Processing An Enhancement For AS/400 DMAS from  Copyright I/O International, 2001, 2005, 2008, 2012 Skip Intro Version.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Chapter 2 –Visual Basic, Controls, and Events
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
© 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,
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 31 Visual Basic Controls A Form is a windows-style screen displayed by Visual Basic programs. In a form, a programmer can create objects in a form.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
IE 411/511: Visual Programming for Industrial Applications
Lecture 7: WinForms & Controls, Part MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Visual Studio.NET ships with a wealth.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
XP New Perspectives on Microsoft Windows 2000 Professional Windows 2000 Tutorial 1 1 Microsoft Windows 2000 Professional Tutorial 1 – Exploring the Basics.
Lecture 6: Introduction to Graphical User Interfaces (GUIs)
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Introduction to Visual Studio & GUI Programming Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
C# GUI - Basics. Objectives.NET supports two types: WinForms, traditional, desktop GUI apps. WebForms – newer, for Web apps. Visual Studio.NET supports.
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.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 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.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 4: Intro to GUIs and the.
GUI Programming Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Chapter 1: An Introduction to Visual Basic .NET
Chapter 2 – Introduction to the Visual Studio .NET IDE
Program and Graphical User Interface Design
6. WinForms 2003 C# GUI - Basics.
Presentation transcript:

6. WinForms: GUI Programming in.NET

2 Microsoft Objectives.NET supports two types of form-based apps, WinForms and WebForms. WinForms are the traditional, desktop GUI apps. The great news is that Visual Studio.NET enables quick, drag-and- drop construction of form-based applications… Event-driven, code-behind programming Visual Studio.NET WinForms Controls

3 Microsoft Part 1 Event-driven, code-behind programming…

4 Microsoft Event-driven applications Idea is very simple: –individual user actions are translated into events –events are passed, 1 by 1, to application for processing –this is how most GUIs are programmed… GUI App

5 Microsoft GUI-based events Mouse move Mouse click Mouse double-click Key press Button click Menu selection Change in focus Window activation etc.

6 Microsoft Code-behind Events are handled by methods that live behind visual interface –known as "code-behind" –our job is to program these methods…

7 Microsoft Call-backs Events are a call from object back to us… How is connection made? –setup by code auto-generated by Visual Studio

8 Microsoft Part 2 Visual Studio.NET…

9 Microsoft Visual Studio.NET (VS.NET) A single IDE for all forms of.NET development –from class libraries to form-based apps to web services –and using C#, VB, C++, J#, etc.

10 Microsoft Basic operation Visual Studio operates in one of 3 modes: 1)design 2)run 3)break When in doubt, check the title bar of VS… designrunbreak

11 Microsoft Example: a windowing application GUI apps are based on the notion of forms and controls… –a form represents a window –a form contains 0 or more controls –a control interacts with the user Let's create a GUI app in a series of steps…

12 Microsoft Step 1 Create a new project of type Windows Application –a form will be created for you automatically…

13 Microsoft Step 2 GUI design Select desired controls from toolbox… –hover mouse over toolbox to reveal –drag-and-drop onto form –position and resize control

14 Microsoft GUI design contd… A simple calculator: Position and configure controls –click to select –set properties via Properties window

15 Microsoft Step 3 code design Code behind the form… Double-click the control you want to program –reveals coding window

16 Microsoft Step 4 run mode Run!

17 Microsoft Break mode? Easily triggered in this application via invalid input…

18 Microsoft Working with Visual Studio In Visual Studio, you work in terms of source files, projects & solutions Source files contain code –end in.cs,.vb, etc. Project files represent 1 assembly –used by VS to keep track of source files –all source files must be in the same language –end in.csproj,.vbproj, etc. Solution (*.sln) files keep track of projects –so you can work on multiple projects

19 Microsoft Part 3 WinForms…

20 Microsoft WinForms Another name for traditional, Windows-like GUI applications –vs. WebForms, which are web-based Implemented using FCL –hence portable to any.NET platform

21 Microsoft Abstraction FCL acts as a layer of abstraction –separates WinForm app from underlying platform System.Windows.Forms.Form CLR Windows OS instance of FCL class object

22 Microsoft Form properties Form properties typically control visual appearance: – AutoScroll – BackgroundImage – ControlBox – FormBorderStyle (sizable?) – Icon – Location – Size – StartPosition – Text (i.e. window's caption) – WindowState (minimized, maximized, normal) Form1 form; form = new Form1(); form.WindowState = FormWindowState.Maximized; form.Show();

23 Microsoft Form methods Actions you can perform on a form: – Activate :give this form the focus – Close :close & release associated resources – Hide :hide, but retain resources to show form later – Refresh :redraw – Show :make form visible on the screen, & activate – ShowDialog : show modally form.Hide();. form.Show();

24 Microsoft Form events Events you can respond to: –bring up properties window –double-click on event name – Load :occurs just before form is shown for first time – Closing :occurs as form is being closed (ability to cancel) – Closed :occurs as form is definitely being closed – Resize :occurs after user resizes form – Click :occurs when user clicks on form's background – KeyPress : occurs when form has focus & user presses key

25 Microsoft Example Ask user before closing form: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { DialogResult r; r = MessageBox.Show("Do you really want to close?", "MyApp", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (r == DialogResult.No) e.Cancel = true; }

26 Microsoft Part 4 Controls…

27 Microsoft Controls User-interface objects on the form: –labels –buttons –text boxes –menus –list & combo boxes –option buttons –check boxes –etc.

28 Microsoft Abstraction Like forms, controls are based on classes in the FCL: –System.Windows.Forms.Label –System.Windows.Forms.TextBox –System.Windows.Forms.Button –etc. Controls are instances of these classes object

29 Microsoft Who creates all these objects? Who is responsible for creating control instances? –code is auto-generated by Visual Studio –when form object is created, controls are then created…

30 Microsoft Naming conventions Set control's name via Name property A common naming scheme is based on prefixes: – cmdOK refers to a command button control – lstNames refers to a list box control – txtFirstName refers to a text box control

31 Microsoft Labels For static display of text –used to label other things on the form –used to display read-only results Interesting properties: – Text :what user sees – Font :how he/she sees it

32 Microsoft Command buttons For the user to click & perform a task Interesting properties: – Text :what user sees – Font :how he/she sees it – Enabled :can it be clicked Interesting events: – Click :occurs when button is "pressed" private void cmdAdd_Click(...) { int i, j, k; i = System.Convert.ToInt32( this.txtNum1.Text ); j = System.Convert.ToInt32( this.txtNum2.Text ); k = i + j; MessageBox.Show( "Sum = " + k.ToString() ); }

33 Microsoft Text boxes Most commonly used control! –for displaying text –for data entry Lots of interesting features…

34 Microsoft Text box properties Basic properties: – Text :denotes the entire contents of text box (a string) – Modified :has text been modified by user? (True / False) – ReadOnly : set if you want user to view text, but not modify Do you want multi-line text boxes? – MultiLine :True allows multiple lines of text – Lines :array of strings, one for each line in text box – ScrollBars :none, horizontal, vertical, or both

35 Microsoft Text box events Interesting events: – Enter, Leave :occurs on change in focus – KeyPress :occurs on ascii keypress – KeyDown, KeyUp :occurs on any key combination – TextChanged :occurs whenever text is modified – Validating and Validated Validating gives you a chance to cancel on invalid input

36 Microsoft Customer[] customers;.. // create & fill array with objects.... // display customers in list box foreach (Customer c in customers) this.listBox1.Items.Add(c); List Boxes Great for displaying / maintaining list of data –list of strings –list of objects (list box calls ToString() to display) // display name of selected customer (if any) Customer c; c = (Customer) this.listBox1.SelectedItem; if (c == null) return; else MessageBox.Show(c.Name);

37 Microsoft Just the tip of the iceberg… Menus, dialogs, toolbars, etc. Thousands of additional controls –.NET and ActiveX –right-click on Toolbox –"Customize Toolbox"

38 Microsoft Summary Event-driven programming is very intuitive for GUI apps Forms are the first step in GUI design –each form represents a window on the screen –form designer enables drag-and-drop GUI construction Users interact primarily with form's controls –labels, text boxes, buttons, etc. –implies that GUI programming is control programming

39 Microsoft References Books: –R. Grimes, "Developing Applications with Visual Studio.NET" Best books on building GUIs are VB-based: –J. Savage, "The VB.NET Coach" (introductory) –F. Balena, "Programming Microsoft VB.NET (Core Reference)" (broad coverage, intermediate level)

40 Microsoft Lab? Work on lab #3, "WinForms"…