Lecture Set 11 Creating and Using Classes

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

Using VB with MS Applications R. Juhl, Delta College.
The Web Warrior Guide to Web Design Technologies
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
ASP.NET Programming with C# and SQL Server First Edition
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Lecture Set 3 Introduction to Visual Basic Concepts Part A – User Interfaces and Windows Forms – The Toolbox.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
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.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Multiple Forms, Standard Modules, And Menus
Multiple Forms and Standard Modules
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
6-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Object-Oriented Programming: Inheritance and Polymorphism.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Chapter 11 An introduction to object-oriented design.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Dive Into® Visual Basic 2010 Express
ASP.NET Forms.
Forms Concepts Triggers Fired when Internal/External events occur
Chapter 2: The Visual Studio .NET Development Environment
Creating Your Own Classes
INF230 Basics in C# Programming
IS 350 Application Structure
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
Chapter 8: Writing Graphical User Interfaces
Multiple Classes and Inheritance
3.01 Apply Controls Associated With Visual Studio Form
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
CSI 101 Elements of Computing – Spring 2009
Using Procedures and Exception Handling
Standard Controls.
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Creating and Using Classes
VISUAL BASIC.
Chapter 6 Multiform Projects
Lecture Set 7 Procedures and Event Handlers
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development Programming with Visual Basic
Multiple Forms, Modules, and Menus
Object-Oriented Programming: Inheritance and Polymorphism
Chapter 15: GUI Applications & Event-Driven Programming
How to organize and document your classes
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Creating and Using Classes
Presentation transcript:

Lecture Set 11 Creating and Using Classes Part A - The Structure of an Application: Modules, and Classes

Objectives Given the specifications for an application that uses classes with any of the members presented in this chapter, develop the application and its classes. To understand the structure of an application and the C# elements in an application List and describe the three layers of a three-layered application. To understand the structure of a class and the elements in a class Describe the concept of encapsulation 1/11/2019 3:49 PM

Objectives (continued) Use class diagrams, the Class View window, and the Class Details window to review, delete, and start the members of the classes in a solution. Use multiple forms and classes to build an application Understand applications with multiple modules 1/11/2019 3:49 PM

Common Application Elements Most Windows applications contain the following elements: Forms (classes defined by you) with event handlers for the tools in the form Other classes defined by the user (but not forms classes) Still other classes from the FCL and other libraries Splash screens (also written as a class) Other “stuff” – Bitmap files Login forms Text files About boxes 1/11/2019 3:49 PM

The Structure of an Application Often viewed in three layers Presentation layer The user interface – forms components Middle Layer The application layer, consisting of components specialized for the applications domain involved Business, University, Games, Bio-medical etc Serves as the intermediary between the presentation and database/files layers Database Layer Components to support the database abstraction SQL, Access, Oracle, other 1/11/2019 3:49 PM

1/11/2019 3:49 PM

Life Made Too Easy (VB) – Adding Classes You can get anything you want at Alice’s restaurant (Arlo Guthrie – from before you were born) You can Add anything you want (to your solution) from Microsoft’s restaurant 1/11/2019 3:49 PM

Common Class Elements – C Sharp Classes contain other elements: Methods – functions in C#, and subs and functions in VB – operations that can be performed by an object. Constructors – special type of method that’s executed when an object is instantiated Data stores Numerous objects of types defined by other classes Variables (of primitive types) Events (and Event handlers -- not always tied to forms) – an event is a signal that notifies other objects that something noteworthy has occurred 1/11/2019 3:49 PM

Common Class Elements (continued) User defined data types – structures, enumerations, complex structured types (arrays of structures, lists or arrays of objects, etc) Delegate - A special type of object that’s used to wire an event to a method Operator - A special type of method that’s performed for a C# operator such as +, -, or =. 1/11/2019 3:49 PM

1/11/2019 3:49 PM

Splash Screens So what is a Splash Screen? You play games? You have seen splash screens  A start-up form that displays while an application is loading (Word and Excel have them – you should be preparing one for your Hangman Game or whatever other game you write) .NET actually provides a ready-made place to specify a Splash Screen C# does not seem to have such a special form 1/11/2019 3:49 PM

Splash Screen for a Game 1/11/2019 3:49 PM

Functions and Access Modifiers Access modifiers control the visibility of procedures A Private function can only be called from the class containing its declaration Functions declared with the Public and We will discuss these access modifiers more in Lecture Set 11C 1/11/2019 3:49 PM

Introduction to Applications with Multiple Components (Classes, Forms) Applications can contain multiple forms, and Classes Each form and Class appears in the Solution Explorer A physical file can contain Classes and multiple forms Forms are implemented as partial classes. The other part of the form class is generated by the Windows Forms Designer and can be examined as a forms.designer file 1/11/2019 3:49 PM

The Solution Explorer Containing Multiple Components 1/11/2019 3:49 PM

Adding a Component to an Application Click Project, Add New Item to activate the Add New Item dialog box Select the item to add from the list of installed templates Class Windows form And many others Assign a name to the new item Note that the templates vary based on the installed Visual Studio edition 1/11/2019 3:49 PM

Operations on Forms Form instances must be created Forms must be displayed Visible forms must be hidden or closed Form events can be handled 1/11/2019 3:49 PM

Creating and Displaying Multiple Form Instances There are three ways to create a form, but we focus on one of these: Explicitly create an instance of the form class and call the Show method to display it The other two ways (not discussed here) include Use the default form instance provided by the My.Forms object Use the default form instance name 1/11/2019 3:49 PM

Creating a Form Instance Explicitly Create a form instance the same way as any class instance would be created Example to create an instance of the form named frmAbout: public class frmAbout : Form { // Inherits the Form class // Methods and data stores unique to this class } // end frmAbout Class // Create new object of type frmAbout frmAbout frmNewInstance = new frmAbout; // Reset the form’s caption frmNewInstance.Text = "About Form“;

Displaying Forms Once created, a form must be displayed A form can be displayed in two ways As a modal form Modal forms must be hidden or closed before the parent form can be displayed Display by calling the ShowDialog method As a modeless form The end user can change input focus between modeless forms at will Display by calling the Show method 1/11/2019 3:49 PM

Displaying Forms (Example) Display a form as a modal dialog box frmAbout.ShowDialog(); Display a form as a modeless dialog box frmAbout.Show(); 1/11/2019 3:49 PM

Hiding and Closing a Form A form can be hidden The objects for a hidden form still exist Call the Hide method to hide a form The Visible property is set to False frmAbout.Hide(); frmAbout.Visible = false; A form can be closed The objects for a closed form are destroyed Call the Close method to close a form this.Close; 1/11/2019 3:49 PM

Introduction to Form Events Events fire as a form gets focus and loses focus The Activated event fires each time a form gets focus The Deactivate event fires each time a form loses focus The Load event fires when a form is loaded into memory The FormClosing event fires just before a form is unloaded from memory After a form has closed, the FormClosed event fires 1/11/2019 3:49 PM

Order of Form Events 1/11/2019 3:49 PM

Viewing Class Attributes You can view a project’s classes and each classes attributes (fields, methods, and properties) by Right clicking on the project name (the second line in the Solution Explorer window) Left clicking on the View Class Diagram entry in the resulting drop down menu An example follows 

1/11/2019 3:49 PM