Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglas...
Multiform Projects Chapter 6 McGraw-Hill © 2006 The McGraw-Hill Companies, Inc. All rights reserved.
Objectives <ul><li>Include multiple forms in an application </li></ul><ul><li>Use templates to create  splash screens  and...
Using Multiple Forms <ul><li>Projects can appear more professional when using different windows for different type of info...
Creating New Forms <ul><li>Select Add Windows Form from the Project menu and select from many installed templates </li></ul>
Switching Between Forms  (1 of 2) <ul><li>In design time there are several ways to switch between forms: </li></ul><ul><ul...
Switching Between Forms  (2 of 2) Using Tabs Selecting from drop down list
Adding Existing From Files  <ul><li>Forms may be used in more than one project-an existing form maybe used in a new projec...
Removing Forms from a Project <ul><li>Select the file name in the Solution Explorer of the file to be removed </li></ul><u...
An About Box  (1of 2) <ul><li>One popular type of form in a project is an  About box  -found in most Windows programs unde...
An About Box  (2 of 2)
Using the About Box Template <ul><li>Visual Studio’s About Box template can be used to create a new About box </li></ul><u...
Setting Assembly Information <ul><li>Users can manually set the Text properties of the controls  </li></ul><ul><li>--OR-- ...
Assembly Information Dialog Box
A Splash Screen <ul><li>The initial screen containing a logo or window that is seen while a program is loading </li></ul><...
Splash Screen Example
Using the Splash Screen Template <ul><li>Visual Studio contains splash screen templates </li></ul><ul><li>Select Project/A...
Making the Splash Form Display First <ul><li>Display the Project Designer from the Project menu and set the Splash screen ...
Setting the Splash Screen Example Set the Splash screen drop-down list to the new form in the Project Designer
Showing a Form <ul><li>New forms are displayed in response to a user clicking a button or a menu item </li></ul><ul><li>In...
Modal versus Modeless Forms <ul><li>Show method displays a form as  modeless -means that both forms are open and the user ...
Show Method <ul><li>General Form </li></ul><ul><li>Example </li></ul><ul><li>The Show method creates a form object from th...
ShowDialog Method <ul><li>General Form </li></ul><ul><li>Example </li></ul><ul><li>Use the ShowDialog method when the user...
Hiding or Closing a Form <ul><li>The Close method behaves differently for a modeless form compared to a modal form </li></...
Hide Method <ul><li>General Form </li></ul><ul><li>Example </li></ul>formName .Hide() summaryForm .Hide()
Responding to Form Events <ul><li>Two primary events that code might be needed for are: </li></ul><ul><ul><li>FormName.Loa...
The Sequence of Form Events Occurs after the form is closed FomClosed Occurs as the form is about to close FormClosing Occ...
Writing Event Procedures  From the Code Editor <ul><li>In the Editor, drop down the Class Name list and choose the entry t...
Writing Event Procedures  From the Properties Window in the Designer <ul><li>Select an event using the Properties window <...
Holding the Splash Screen Display <ul><li>If application are very small the splash screen disappears before it can be read...
Variables/Constants in Multiform Projects <ul><li>For module-level variables to be available in more than one form in a pr...
Access Level <ul><li>Specifies the permission required to make use of the variable or constant </li></ul><ul><li>To make a...
Lifetime <ul><li>The period of time that a variable or constant remains in existence </li></ul><ul><li>Module and  namespa...
Static Variables <ul><li>Use to declare local and block level variables </li></ul><ul><li>Retain their value for the life ...
The Static Statement <ul><li>General Form </li></ul><ul><li>Examples </li></ul>Static Identifier As DataType Static person...
Namespaces <ul><li>VB projects are automatically assigned to a namespace </li></ul><ul><ul><li>Namespaces can be viewed an...
Declaring Variables/Constants Guidelines <ul><li>Place all local declarations at the top of a procedure </li></ul><ul><li>...
Running a Program Outside the IDE <ul><li>The .exe file can be moved to another computer, placed on the system desktop, or...
Upcoming SlideShare
Loading in …5
×

Chapter 06

725 views

Published on

Published in: Education, Sports, Technology
  • Be the first to comment

  • Be the first to like this

Chapter 06

  1. 1. aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf
  2. 2. Multiform Projects Chapter 6 McGraw-Hill © 2006 The McGraw-Hill Companies, Inc. All rights reserved.
  3. 3. Objectives <ul><li>Include multiple forms in an application </li></ul><ul><li>Use templates to create splash screens and about boxes </li></ul><ul><li>Use the Show, ShowDialog, and Hide method s to display and hide forms </li></ul><ul><li>Understand the various form events and select the best procedure for your code </li></ul><ul><li>Declare variables with the correct scope and access level for multiform projects </li></ul>
  4. 4. Using Multiple Forms <ul><li>Projects can appear more professional when using different windows for different type of information </li></ul><ul><li>The first form a project displays is a summary form </li></ul><ul><li>Projects can contain as many forms as desired </li></ul>
  5. 5. Creating New Forms <ul><li>Select Add Windows Form from the Project menu and select from many installed templates </li></ul>
  6. 6. Switching Between Forms (1 of 2) <ul><li>In design time there are several ways to switch between forms: </li></ul><ul><ul><li>Solution Explorer window-select a form name and click the View Designer button or the View Code button </li></ul></ul><ul><ul><li>Double-clicking a form name opens the form in designer </li></ul></ul><ul><ul><li>Easiest way is to use the tabs at the top of the Document window that appear when the form is displayed </li></ul></ul><ul><li>Each form is a separate file and a separate class </li></ul>
  7. 7. Switching Between Forms (2 of 2) Using Tabs Selecting from drop down list
  8. 8. Adding Existing From Files <ul><li>Forms may be used in more than one project-an existing form maybe used in a new project </li></ul><ul><li>Each form and information for the form is saved as three separate files: </li></ul><ul><ul><li>Code procedures </li></ul></ul><ul><ul><li>Visual interface </li></ul></ul><ul><ul><li>Property settings for the controls </li></ul></ul><ul><li>To add an existing form to a project use the Add Existing Item command on the Project menu </li></ul><ul><ul><li>Select only one filename: FormName.vb; all three files are automatically copied into the project folder </li></ul></ul>
  9. 9. Removing Forms from a Project <ul><li>Select the file name in the Solution Explorer of the file to be removed </li></ul><ul><li>Either click the Delete key or right-click on the filename to and choose Delete form the context menu </li></ul><ul><li>Additional option is to choose Exclude from project to remove the form from the project but not delete the files </li></ul>
  10. 10. An About Box (1of 2) <ul><li>One popular type of form in a project is an About box -found in most Windows programs under Help/About </li></ul><ul><li>Usually provides the name and version of the program and information about the programmer or company </li></ul><ul><li>Users can create About boxes by creating a new form and entering the information in labels </li></ul><ul><li>Windows controls can be used on a new form </li></ul>
  11. 11. An About Box (2 of 2)
  12. 12. Using the About Box Template <ul><li>Visual Studio’s About Box template can be used to create a new About box </li></ul><ul><li>Choose Add Windows Form from the Project menu and select About Box </li></ul>
  13. 13. Setting Assembly Information <ul><li>Users can manually set the Text properties of the controls </li></ul><ul><li>--OR-- </li></ul><ul><li>Open the Project Designer from Project/ProjectName Properties or double-click the My Project in the Solution Explorer </li></ul><ul><ul><li>Click the Assembly Information button and fill in the desired information in the Assembly Information dialog box </li></ul></ul>
  14. 14. Assembly Information Dialog Box
  15. 15. A Splash Screen <ul><li>The initial screen containing a logo or window that is seen while a program is loading </li></ul><ul><li>Professional applications use splash screens to tell the user that the program is loading or starting </li></ul><ul><li>Makes a large application appear to load and run faster since something is displaying on the screen while the rest of the application loads </li></ul>
  16. 16. Splash Screen Example
  17. 17. Using the Splash Screen Template <ul><li>Visual Studio contains splash screen templates </li></ul><ul><li>Select Project/Add New Item to display the Add new item dialog box and choose Splash Screen </li></ul><ul><li>Modify the form to fit current needs </li></ul>A splash form created using the Splash Screen template
  18. 18. Making the Splash Form Display First <ul><li>Display the Project Designer from the Project menu and set the Splash screen drop-down list to the created splash screen </li></ul><ul><li>Do not change the setting for Startup object or Shutdown mode </li></ul><ul><li>Then the project is run, the splash screen should display while the startup form is loading and then disappear </li></ul><ul><li>At times the startup forms loads so quickly that it is nearly impossible to see the splash screen </li></ul>
  19. 19. Setting the Splash Screen Example Set the Splash screen drop-down list to the new form in the Project Designer
  20. 20. Showing a Form <ul><li>New forms are displayed in response to a user clicking a button or a menu item </li></ul><ul><li>In the event procedure for the button or menu item use either the Show method or ShowDialog method to display the new form </li></ul>
  21. 21. Modal versus Modeless Forms <ul><li>Show method displays a form as modeless -means that both forms are open and the user can navigate from one form to the other </li></ul><ul><li>ShowDialog method displays a new form as modal -the user must respond to the form in some way, usually by clicking a button </li></ul><ul><ul><li>No other program code can execute until the user responds to and hides or closes the modal form </li></ul></ul><ul><li>With a modeless form the user may switch to another form in the project without responding to the form </li></ul>
  22. 22. Show Method <ul><li>General Form </li></ul><ul><li>Example </li></ul><ul><li>The Show method creates a form object from the specified class and displays it modelessly-the formName is the name of the form to be displayed </li></ul>f ormName .Show () summaryForm.Show ()
  23. 23. ShowDialog Method <ul><li>General Form </li></ul><ul><li>Example </li></ul><ul><li>Use the ShowDialog method when the user is wanted to notice, respond to, and close the form before proceeding with the application-this code is generally placed in a menu item or a button’s click even procedure </li></ul>f ormName .ShowDialog () summaryForm.ShowDialog ()
  24. 24. Hiding or Closing a Form <ul><li>The Close method behaves differently for a modeless form compared to a modal form </li></ul><ul><ul><li>Modeless-Close destroys the form instance and removes it from memory </li></ul></ul><ul><ul><li>Modal-the form is only hidden </li></ul></ul><ul><li>Choosing a form’s Hide method sets the form’s Visible property to False and keeps the form instance in memory ready to be re-displayed </li></ul><ul><ul><li>An example would be for form with instructions or Help text </li></ul></ul>
  25. 25. Hide Method <ul><li>General Form </li></ul><ul><li>Example </li></ul>formName .Hide() summaryForm .Hide()
  26. 26. Responding to Form Events <ul><li>Two primary events that code might be needed for are: </li></ul><ul><ul><li>FormName.Load-form loaded into memory </li></ul></ul><ul><ul><li>FormName.Activated-occurs when control is passed to form </li></ul></ul><ul><li>First time a form is shown in an application the form generates both the Load and Activated events </li></ul><ul><li>If a form is displayed multiple times, initializing steps can be placed into the Activated event procedure; same for setting the focus in a particular place on a new form </li></ul>
  27. 27. The Sequence of Form Events Occurs after the form is closed FomClosed Occurs as the form is about to close FormClosing Occurs when the form is no longer the active form Deactivate Occurs each time any portion of the form is redrawn Paint Occurs each time the form is shown Activate Occurs before the form is displayed for the first time-usually happens only once Load
  28. 28. Writing Event Procedures From the Code Editor <ul><li>In the Editor, drop down the Class Name list and choose the entry that shows the events for the selected form </li></ul><ul><li>In the Method Name list select the event for which to write a procedure—events already having a written procedure appear in bold </li></ul>
  29. 29. Writing Event Procedures From the Properties Window in the Designer <ul><li>Select an event using the Properties window </li></ul><ul><li>Click the form to show properties and click Events button </li></ul><ul><li>Double-click the event to create an empty event procedure </li></ul>
  30. 30. Holding the Splash Screen Display <ul><li>If application are very small the splash screen disappears before it can be read </li></ul><ul><li>Code can be written to hold the splash screen longer </li></ul>
  31. 31. Variables/Constants in Multiform Projects <ul><li>For module-level variables to be available in more than one form in a project it must be declared as Friend or Public and not as Private </li></ul><ul><li>Scope can be expanded for variable and constants and is the set of statements that can access a variable or constant without qualifying its name </li></ul>
  32. 32. Access Level <ul><li>Specifies the permission required to make use of the variable or constant </li></ul><ul><li>To make a variable available to other forms use either the Public or Friend keywords </li></ul><ul><ul><li>Friend-allows other forms in the project to access the variable </li></ul></ul><ul><ul><li>Public-allows all other programs to access variables </li></ul></ul><ul><li>Private keyword allows access only in the class (form) in which it is declared </li></ul><ul><li>Only use access level keywords for module level variable </li></ul>
  33. 33. Lifetime <ul><li>The period of time that a variable or constant remains in existence </li></ul><ul><li>Module and namespace variables exist as long as the application runs </li></ul>
  34. 34. Static Variables <ul><li>Use to declare local and block level variables </li></ul><ul><li>Retain their value for the life of the project </li></ul><ul><li>If the value in a variable needs to be retained for multiple calls to a procedure such as running count, declare it as Static </li></ul><ul><li>If the variable is used in multiple procedures, declare it at the module level </li></ul>
  35. 35. The Static Statement <ul><li>General Form </li></ul><ul><li>Examples </li></ul>Static Identifier As DataType Static personCountInteger As Integer Statis reportTotalDecimal As Decimal
  36. 36. Namespaces <ul><li>VB projects are automatically assigned to a namespace </li></ul><ul><ul><li>Namespaces can be viewed and modified which is called the root namespace </li></ul></ul>
  37. 37. Declaring Variables/Constants Guidelines <ul><li>Place all local declarations at the top of a procedure </li></ul><ul><li>Use named constants for any value that doesn’t change during the program execution </li></ul><ul><li>Keep the scope of variables and constants narrow </li></ul><ul><li>Consider making variables local if possible </li></ul><ul><li>Make variables Static if needed for multiple executions within a procedure </li></ul><ul><li>If variables are needed for more than one procedure, declare it as local and pass it as an argument </li></ul><ul><li>Use Private module level variables if using a variable in multiple procedures and displaying in another </li></ul><ul><li>If using the value of a variable in more than one form declare it as Friend </li></ul>
  38. 38. Running a Program Outside the IDE <ul><li>The .exe file can be moved to another computer, placed on the system desktop, or used as a shortcut just like any other application </li></ul><ul><li>If copying the .exe file to another system make sure it has the Microsoft.NET Framework </li></ul><ul><ul><li>Can download the framework for free from the Microsoft </li></ul></ul><ul><ul><li>Web site </li></ul></ul><ul><li>Change the icon if desired </li></ul>

×