Visual C# 2012 How to Program ©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Advertisements

© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
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.
GUI-Labels, TextBoxes and Buttons Label- displays read-only text Common properties:  Font – font used by the text of label  Text – text to appear on.
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#
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
 2006 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part I.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Visual Basic Chapter 1 Mr. Wangler.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
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.
Week 2: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
 2009 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2008 IDE.
 2009 Pearson Education, Inc. All rights reserved Dive Into ® Visual C# 2008 Express.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Visual C# 2012 How to Program 1. 2  A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
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.
Topics Introduction Scene Graphs
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
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.
 2009 Pearson Education, Inc. All rights reserved. 1 CS1120 Introduction to Windows Forms Applications Many slides modified by Prof. L. Lilien (even many.
 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.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
 2007 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part 1.
Dive Into® Visual Basic 2010 Express
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Visual Basic.NET Windows Programming
Chapter 2 – Introduction to the Visual Studio .NET IDE
Graphical User Interface Concepts: Part I
1. Introduction to Visual Basic
Chapter 2 Visual Basic Interface
Program and Graphical User Interface Design
Graphical User Interface Concepts: Part I
Chapter 14 Graphical User Interfaces with Windows Forms: Part 1
Visual C# - GUI and controls - 1
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Week 2: WINDOWS PROGRAMMING
Presentation transcript:

Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.

 A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual Studio Express window containing various GUI controls. © by Pearson Education, Inc. All Rights Reserved.

 GUI controls are objects that can display information on the screen or enable users to interact with an app.  Several common GUI controls are listed in Fig © by Pearson Education, Inc. All Rights Reserved.

 A Form is a graphical element that appears on your computer’s desktop; it can be a dialog, a window or an MDI window.  A component is an instance of a class that implements the IComponent interface, which defines the behaviors that components must implement, such as how the component is loaded.  A control, such as a Button or Label, has a graphical representation at runtime. © by Pearson Education, Inc. All Rights Reserved.

 Figure 14.3 displays the Windows Forms controls and components from the C# Toolbox.  To add a control or component, select it from the Toolbox and drag it onto the Form. © by Pearson Education, Inc. All Rights Reserved.

 The active window is the frontmost and has a highlighted title bar.  A window becomes the active window when the user clicks somewhere inside it.  A Form is a container for controls and components.  When you drag items from the Toolbox onto the Form, Visual Studio generates code that creates the object and sets its basic properties.  The IDE maintains the generated code in a separate file using partial classes. © by Pearson Education, Inc. All Rights Reserved.

 Figure 14.4 lists common Form properties, common methods and a common event. © by Pearson Education, Inc. All Rights Reserved.

 GUIs are event driven.  When the user interacts with a GUI component, the event drives the program to perform a task.  A method that performs a task in response to an event is called an event handler. © by Pearson Education, Inc. All Rights Reserved.

A Simple Event-Driven GUI  The Form in the app of Fig contains a Button that a user can click to display a MessageBox. © by Pearson Education, Inc. All Rights Reserved.

Adding an Event Handler for the Button ’s Click Event  To create the app’s event handler, double click the Button on the Form.  The following empty event handler is declared: private void clickButton_Click ( object sender, EventArgs e ) { }  By convention, the IDE names the event-handler method as objectName _ eventName (e.g., clickButton_Click ). © by Pearson Education, Inc. All Rights Reserved.

Event Handler Parameters  Each event handler receives two parameters when it’s called:  This first—an object reference typically named sender — is a reference to the object that generated the event.  The second is a reference to an EventArgs object (or an object of an EventArgs derived class) which contains additional information about the event. © by Pearson Education, Inc. All Rights Reserved.

Auto-Generated GUI Code  Visual Studio places the auto-generated code in the Designer.cs file of the Form.  Open this file by expanding the node in the Solution Explorer window for the file you’re currently working in ( SimpleEventExampleForm.cs ) and double clicking the file name that ends with Designer.cs. © by Pearson Education, Inc. All Rights Reserved.

Since this code (Figs and 14.7) is created and maintained by Visual Studio, you generally don’t need to look at it. © by Pearson Education, Inc. All Rights Reserved.

Another Way to Create Event Handlers Using the Properties Window to Create Event Handlers  Controls can generate many different events.  Clicking the Events icon (the lightning-bolt icon) in the Properties window (Fig. 14.8), displays all the events for the selected control. © by Pearson Education, Inc. All Rights Reserved.

Locating Event Information  Read the Visual Studio documentation to learn about the different events raised by each control.  To do this, select a control in the IDE and press the F1 key to display that control’s online help (Fig. 14.9).  The web page that's displayed contains basic information about the control’s class. © by Pearson Education, Inc. All Rights Reserved.

 Controls derive from class Control (namespace System.Windows.Forms ).  Figure lists some of class Control ’s properties and methods. © by Pearson Education, Inc. All Rights Reserved.

Anchoring and Docking  Anchoring causes controls to remain at a fixed distance from the sides of the container.  Anchor a control to the right and bottom sides by setting the Anchor property (Fig ). © by Pearson Education, Inc. All Rights Reserved.

 Execute the app and enlarge the Form (Fig ). © by Pearson Education, Inc. All Rights Reserved.

 Docking attaches a control to a container such that the control stretches across an entire side or fills an entire area.  Docking allows a control to span an entire side of its parent container or to fill the entire container (Fig ).  The Form ’s Padding property specifies the distance between the docked controls and the edges. © by Pearson Education, Inc. All Rights Reserved.

Using Visual Studio To Edit a GUI’s Layout  Visual Studio provides tools that help you with GUI layout.  When dragging a control across a Form, blue lines (known as snap lines) help you position the control (Fig ).  Visual Studio also provides the FORMAT menu, which contains several options for modifying your GUI’s layout. © by Pearson Education, Inc. All Rights Reserved.

 Label displays text that the user cannot directly modify.  Figure 14.7 lists common Label properties. © by Pearson Education, Inc. All Rights Reserved.

 A TextBox (Fig ) is an area in which either text can be displayed by a program or the user can type text via the keyboard.  If you set the property UseSystemPasswordChar to True, the TextBox becomes a password TextBox. © by Pearson Education, Inc. All Rights Reserved.

 A button is a control that the user clicks to trigger a specific action or to select an option in a program.  A program can use several types of buttons, but all the button classes derive from class ButtonBase. © by Pearson Education, Inc. All Rights Reserved.

 Figure lists common properties and a common eventof class Button. © by Pearson Education, Inc. All Rights Reserved.

 Figure uses a TextBox, a Button and a Label. © by Pearson Education, Inc. All Rights Reserved.

 GroupBoxes and Panel s arrange related controls on a GUI.  All of the controls in a GroupBox or Panel move together when the GroupBox or Panel is moved.  The primary difference is that GroupBox es can display a caption and do not include scrollbars, whereas Panel s can include scrollbars and do not include a caption. © by Pearson Education, Inc. All Rights Reserved.

 To create a GroupBox or Panel, drag its icon from the Toolbox onto a Form.  Then, drag new controls from the Toolbox directly into the GroupBox or Panel.  To enable the scrollbars, set the Panel ’s AutoScroll property to true.  If the Panel cannot display all of its controls, scrollbars appear (Fig ). © by Pearson Education, Inc. All Rights Reserved.

 The program in Fig uses a GroupBox and a Panel to arrange Button s. © by Pearson Education, Inc. All Rights Reserved.

CheckBox es  A CheckBox is a small square that either is blank or contains a check mark.  You can also configure a CheckBox to toggle between three states by setting its Three­State property to True.  Any number of CheckBox es can be selected at a time. © by Pearson Education, Inc. All Rights Reserved.

 The program in Fig allows the user to select CheckBoxes to change a Label’s font style. © by Pearson Education, Inc. All Rights Reserved.

 To change the font style on a Label, you must set its Font property to a new Font object.  The Font constructor we used takes the current font and the new style as arguments. Combining Font Styles with Bitwise Operators  Styles can be combined via bitwise operators — operators that perform manipulation on bits of information.  We needed to set the FontStyle so that the text appears in bold if it was not bold originally, and vice versa  The logical exclusive OR operator makes toggling the text style simple. © by Pearson Education, Inc. All Rights Reserved.

RadioButtons  Radio buttons are similar to CheckBox es in that they also have two states—selected and not selected.  RadioButton s normally appear as a group, in which only one RadioButton can be selected at a time.  All RadioButton s added to a container become part of the same group. © by Pearson Education, Inc. All Rights Reserved.

 The program in Fig uses RadioButtons to enable users to select options for a MessageBox. © by Pearson Education, Inc. All Rights Reserved.