Multi-Form Applications Things You Need to Know

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

Tutorial 12: Enhancing Excel with Visual Basic for Applications
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 2 –Visual Basic, Controls, and Events
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Chapter 2 –Visual Basic, Controls, and Events
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Multiple Forms, Standard Modules, And Menus
Multiple Forms and Standard Modules
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
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
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 12: How Long Can This Go On?
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
6-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
E-Commerce: Introduction to ASP.Net Application Architecture 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Multiple Forms and Menus
Chapter 1: An Introduction to Visual Basic .NET
PictureBox, MessageBox, Multiple Forms, Splash Screens and Timers
Visual Basic.NET Windows Programming
A variable is a name for a value stored in memory.
Chapter 2: The Visual Studio .NET Development Environment
IS 350 Application Structure
Chapter 1: An Introduction to Visual Basic 2015
Apply Procedures to Develop Message, Input, and Dialog Boxes
3.01 Apply Controls Associated With Visual Studio Form
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Chapter 1: An Introduction to Visual Basic 2015
Using Procedures and Exception Handling
Variables and Arithmetic Operations
Multi-form applications and dialogs
Chapter 6 Multiform Projects
Topics Introduction to File Input and Output
CIS16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Tonga Institute of Higher Education
Additional Topics in VB.NET
Object-Oriented Programming: Inheritance and Polymorphism
Introduction to Programming
Topics Introduction to File Input and Output
Brief description on how to navigate within this presentation (ppt)
Creating Additional Input Items
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Multi-Form Applications Things You Need to Know ISM 3005 Course Introduction Topics Multi-Form Applications Things You Need to Know Application Form Management When the Application Ends Opening Another Form and Returning Communicating Between Forms Dialogs “Never let a computer know you’re in a hurry” Unknown 2

Multi-Form Applications Most applications require multiple forms More than one task performed under the application umbrella Multi-step tasks Too much information to fit on a single form The user should almost never be able to switch between different concurrently open windows

Multi-Form Applications You must take careful control over forms What the user sees When the application ends Which form opens first Which forms are open at any particular time Which forms are open and visible Which forms are open and invisible You need to avoid leaving an application running but with no visible forms

Things You Need to Know How to create a new form How to change the startup form for a project How closing forms can end the program How closing forms can leave a program running with no visible form How to set values on one form from another one How to create an object variable referencing a form and use it to open and communicate with a form The difference between referencing an object variable version of a form and the form directly

Things You Need to Know (cont.) How to use Dialog Boxes and predefined form types How to create a custom dialog box form How to call a custom dialog form from multiple forms and have the dialog update the proper calling form How to set up a splash screen

Planning the Project’s Navigation Top-Down menu navigation All other forms are reached from the main menu Navigation always returns to the main menu May have subordinate levels of menu Consider only letting top level menu end the application Other forms will Close Return to the top menu

Planning the Project’s Navigation (cont.) Multi-step task requires navigating through a sequence of forms Return to top level menu from a different form than the one directly reached

Planning the Project’s Navigation (cont.) Multiple Paths Some forms may be reached from different forms

Planning the Project’s Navigation (cont.) The navigation approaches needed have implications for how you open and close forms Some needs may have multiple techniques Some techniques may not be suitable for some navigation needs

Form File Names When a new project is created it will automatically get a form called Form1 with a file name of Form1.vb The only way to take control of the form’s file name is to delete the default form and create a new one Set the new form’s name when it is created This will also be the file name Change the Project Startup Form Choose Project | Properties from the menu

1 Adding a New Form 2 Add a new form in the Solution Explorer Right-click the project Select Add Select Windows Form… Set the form’s name and file name in the resulting dialog (If the application is large enough you should use folders to organize it) 3

Project Properties Use the Project | Properties … menu to set project form properties Start up form Always set this if you remove Form1 as first form Shutdown mode Determines when form closing ends the application I recommend “When Last Form Closes” choice

Showing a Form Three techniques to make a form visible FormName.Show Any code in the procedure following this statement will continue to execute User can click on either form FormName.ShowDialog Execution of code in the current procedure is paused until the called form is closed User cannot address any other form FromName.Visible = True (do not use)

Navigation Techniques You should almost never have more than one form active and available to the user at a time If Form A calls Form B you can make Form A unavailable in four ways Close Form A (FormA.Close) Make Form A invisible (FormA.Visible = False) Disable Form A (FormA.Enabled = False) Show Form B “modally” in dialog form FormB.ShowDialog Approaches 1 & 2hide Form A while 3 & 4 leave Form A visible but unavailable

Navigation Techniques (cont.) If you close the last open form you will end the application If you set a calling form (Form A) to be invisible or disabled — and — you close Form B You can leave the application running but with no visible form for the user to navigate from User must use Task Manager to end a compiled program Or stop debugging in development mode Some approaches can leave you with multiple copies of the same form open at once!!

Two Ways to Address a Form in Code Refer to the form by it’s name May refer to any public property or method of the form using FormName.PublicPropertyOrMethod FormName.lblCustomerID.Text = … FormName.Show FormName.Text = … Any changes made to a property or value this way Persist as long as the application is running (unless explicitly changed elsewhere)

Two Ways to Address a Form in Code (cont.) Create an object variable instance of the form The copy of the form created in the variable (theFormName in the example above) only lasts as long as the variable is in existence Follows normal variable scoping rules Any settings made to the copy expire when the object variable expires New copies will revert to the form’s definition from design view Dim theFormName as New FormName theFormName.lblCustomerID.Text = … theFormName.Show

Passing Values Between Forms Forms expose certain elements to code on other forms or in other classes or modules All controls Because controls are declared in the form designer scoped with “Friend” Any variable or custom-written property declared with Public Available to any code Friend Available to any code in the same project

Passing Values Between Forms (cont.) Public Class FormB Friend intCustomerID as Integer If the declaration above exists on Form B code on Form A can address intCustomerID directly Any code on Form B can then read this value Common to read the value in the Form Load event but it can be read anywhere Code on other forms can also read the value “Friend” cannot be used in a procedure ‘* Code on Form A FormB.intCustomerID = Convert.ToInt32(txtCustID.Text)

Passing Values Between Forms (cont.) Any form or control property on any form can be set or read by code on another form FormName.PropertyName FormName.ControlName.PropertyName We can also write Friend scoped custom properties for forms Covered in the Object Oriented classes later in the semester

Returning to The Correct Form In a straight hierarchical navigation structure managing return to the correct form is straightforward Form A can use FormB.ShowDialog to show Form B Focus will be returned to Form A when Form B is released Or Form B can explicitly show Form A because it is the only form that will ever open Form B

Returning to the Correct Form (cont.) If both Form A and Form B (or any other form) both open Form C On Form C put this code Public Class FormC Friend theCallingForm As Form Private Sub btnClose_Click... theCallingForm.Show() Me.Close() End Sub End Class Note object declared as type Form

Returning to the Correct Form (cont.) Flexible form navigation (cont.) On the calling form use this code Form C now has a reference to the form that called it Note that you cannot CLOSE the calling form or the called form will have no form reference Private Sub btnFormC_Click... Dim theFormC As New FormC theFormC.theCallingForm = Me theFormC.Show() Me.Visible = False End Sub Do not close the calling form

Dialogs VB comes with a rich collection of dialogs with which to create Interactive mini-forms Input box Message box Special purpose input forms Splash screens About box Explorer form

Dialogs—Message Boxes Message Boxes return a value indicating which button was pushed Button combinations AbortRetryIgnore OK OKCancel RetryCancel YesNo YesNoCancel Return Values 1 = OK 2 = Cancel 3 = Abort 4 = Retry 5 = Ignore 6 = Yes 7 = No

Dialogs—Message Boxes (cont.) Message boxes can be called as a statement or used in a function format to return a value Experiment with the wide variety of icons Avoid using message boxes excessively lblMessageBoxResult.Text = MessageBox.Show("Show the message", _ "Click the Buttons", _ MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button1)

Dialogs—Input Boxes An input box displays a fixed size mini form with OK and Cancel buttons and a single text input area Returns the contents of the text area if the OK button is pressed Returns an empty string If the Cancel button is pressed If the text input area is empty

Dialogs—Custom Dialog Forms Any form can work like a dialog box with any combination of controls Set the form’s .DialogResult property to one of the available DialogResult values Consider setting the MinimizeButton, MaximizeButton, and ControlBox properties to False and set the FormBorderStyle to Fixed Single Private Sub btnOK_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnOK.Click Me.DialogResult = Windows.Forms.DialogResult.OK Me.Close() End Sub

Dialogs—Custom Dialog Forms (cont.) Read the custom dialog form’s .DialogResult property in the calling form and take appropriate action Other public or friend values on the custom dialog form are also available after it has closed Dim theCustomDialog As New CustomDialog theCustomDialog.ShowDialog() If theCustomDialog.DialogResult = Windows.Forms.DialogResult.OK Then lblCustomDialogResult.Text = theCustomDialog.cboColor.Text Else lblCustomDialogResult.Text = "Cancelled“ End If

Dialogs—Built in Dialogs There are several built in dialogs available in VB Each returns a specialized value ColorDialog returns a Color FontDialog returns a Font FileDialog, OpenFileDialog, & SaveFileDialog return a file path See sample code for two examples We will use the file dialogs in the Sequential Data File classes

Splash Screens Many programs have splash screens VB provides a built-in splash screen but I prefer to make my own Requires use of the Timer control Make the splash screen the Start Up form Have the timer tick event open the next form (usually menu) and close the splash screen Hint: Set the timer interval to be very short during development

Timer Controls Timer controls appear in the resource area at the bottom of the form design area Tick property indicates how many clock ticks measured in milliseconds will count down before the timer’s Tick event executes Value of 1000 = one second The timer’s Start method must be called before the timer will start counting The Tick event contains code to run when the specified interval has passed

Miscelaneous Remember to always Open the next form before closing the current form If the project is set to end after the last form closes you could inadvertently end the program Avoid situations where you are leaving open forms behind you Use “Close” or “Menu” to indicate this form will close but you will return to a higher form Use “Exit” to indicate that the program will end It is good practice to have only one place to end the program