Multiple Forms, Standard Modules, And Menus

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Multiple Forms, Standard Modules, And Menus
Tutorial 8: Developing an Excel Application
Chapter 7: Sub and Function Procedures
110-H1 More VB Tools Creating a Menu: What is a menu? a group of (related) commands displayed at at the top of an application Top level menu Disabled command.
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.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 7 Multiple Forms, Modules,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Multiple Forms & Procedures. Form Methods: –Show, Hide, Activate, Close Events: –Load, Activated, Closing, Closed.
Using the Visual Basic Editor Visual Basic for Applications 1.
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.
Multiple Document Interface (MDI) application
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Creating Menu. Objectives Create a menu system for a form –Create a menu –Create a menu titles –Create a menu items –Create a submenu –Modify menu –Edit.
Copyright © 2014 Pearson Education, Inc. Chapter 7 Multiple Forms, Modules, and Menus.
BİL528 – Bilgisayar Programlama II Advanced Controls, Menus, Toolbars, and Status Bars 1.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
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 NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Multiple Forms and Standard Modules
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
| | Tel: | | Computer Training & Personal Development Outlook Express Complete.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
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.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
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.
OCC Network Drives  H:\  P:\ 
Visual Basic.NET BASICS Lesson 3 Events and Code.
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.
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Lesson 3 — Menus, MDIs, and Simple Loops Microsoft Visual Basic.NET, Introduction to Programming.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
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.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
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.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Chapter 7, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 7 Multiple Forms, Standard Modules, And Menus.
Multiple Forms and Menus
PictureBox, MessageBox, Multiple Forms, Splash Screens and Timers
Chapter 6 Multiform Projects
Multiple Forms, Modules, and Menus
Lecture Set 11 Creating and Using Classes
Presentation transcript:

Multiple Forms, Standard Modules, And Menus Chapter 7 Multiple Forms, Standard Modules, And Menus

7.1 Introduction

Chapter 7 Topics How to add multiple forms to a project How to create a standard module To hold procedures and functions That is not associated with a specific form Creating a menu system Context menus With commands and submenus that the user may select from

7.2 Multiple Forms Visual Basic .NET Projects May Have Multiple Forms If One of the Forms Is the Startup Object, It Is Displayed When the Project Executes The Other Forms Are Displayed by Programming Statements

Form Names Each Form has its specific name This name is set/changed with the Name Property Each form also has a file name (.vb) To change the file name: Right click its entry in the Solution Explorer Choose Rename

Adding a New Form Add New Item on the tool bar The Add New Item dialog box appears Click on Windows Form under Templates Change the default name if you wish Click Open

Switching between Design and Code The Design window has the following tabs frmMain.vb[Design] Form Design Itself frmError.vb[Design] Error Form Design frmMain.vb Main Code frmError.vb Error Code

Classes and Instances When you create a Form at design time, you are just creating a general description of a Form (It does not actually exist at that moment) Analogy: It is a blueprint of a Form An Instance must be created to actually have a Form at run time Analogy: What the blueprint describes is actually built

Creating an Instance of a Form It must be declared, syntax: For example: It is still not visible, but a form object has been instantiated Refer to it using the variable errorForm Dim ObjectVariable As New ClassName() Dim errorForm As New frmError()

Modal Form/ShowDialog Method When a Modal Form is displayed, no other form in the application can receive the focus until the modal form is closed Use the ShowDialog Method to display a modal form: errorForm.ShowDialog()

Modeless Form/Show Method A Modeless Form allows the user to switch focus to another form in the same application Use the Show Method to display a modeless form: errorForm.Show()

Closing a Form A form may close itself using the Close Method and referring to itself as "Me": As in Me.Close() Private Sub btnClose_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnClose.Click Me.Close() End Sub

Hiding a Form Closing a Form eliminates it from memory To simply make it not visible, use the Hide Method: To bring it back use the ShowDialog() or Show() Methods Me.Hide()

More About Modal and Modeless statement; messageForm.ShowDialog() ' Statements below will ' not execute until the ' Form is closed statement; messageForm.Show() ' Statements below will ' execute right after the ' Form is displayed

A Form's Load Event The Load Event is triggered just before the form is initially displayed If code needs to execute at this time, it must be contained in that event handling procedure: Private Sub frmMain_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load End Sub

A Form's Activated Event The Activated Event is triggered when the user switches to the from from another form or another application It is also triggered after the Load Event

A Form's Closing Event This Event is triggered as the form is in the process of closing, but before it has closed For instance, one might want to ask the user if they really want the form closed

A Form's Closed Event The Closed Event is triggered after a form is closed Note that it is now too late to prevent the Form from being closed (it is already)

Accessing Objects on a Different Form When code in a form refers to an object, it is assumed that that object is in the same form To refer to an object in another form, preface the object name with the variable name associated with that form: Dim greetingForm As New frmGreeting() greetingForm.lblMessage.Text = "Hello!" greetingForm.ShowDialog()

Class-level Variables and Multiple Forms Class-level variables are Private by default This means they are not accessible by code in other forms If you wish them to be, they must be declared with the Public qualifier: Public total As Single ' Instead of the declaration ' Dim total As Single

Procedures Have Similar Access Rules Procedures, by default, are Public They can be accessed by code outside of their Form To prevent this from happening, declare them to be Private

7.3 Standard Modules A Standard Module Contains Code - Declarations and Procedures - That Are Used by Other Files in a Project

Furthermore, Standard Modules Are not associated with a Form Contain no Event Procedures Are saved in files with a .vb extension Are used to hold code that is used by multiple Forms, or for command-line programs

Standard Module Syntax Module ModuleName [Module Contents] End Module A Module will contain Sub procedures and Functions, they can be Private - only used by functions in that Module Public - can be called from outside of the Module

Module Level Variables These are declared within a Module But not within Functions or Sub procedures in that Module If declared Dim or Private, their scope is the Module (called module scope) If declared Public, their scope is the application (called global scope)

Application with No Startup Form Designate a Public Sub procedure named "Main" as the startup object It must be in a Standard Module When the application starts No Form will be displayed "Main" will be given control

You Use the Menu Designer to Create a Menu System Visual Basic .NET Allows You to Create a System of Drop-down Menus for Any Form in Your Application You Use the Menu Designer to Create a Menu System

Components of a Menu System, I Menu Name Shortcut Key Checked Menu Command Menu Command Separator Bar Submenu

Components of a Menu System, II Menu Names - each drop-down menu has a name Menu Command - the list of actions in the drop-down list Shortcut Key - a key or combinations of keys to activate the command from the keyboard

Components of a Menu System, III Disabled Menu Command - a command that is not applicable is grayed out (and is not selectable) Checked Menu Command - some commands are toggles - checked when on, unchecked when off

Components of a Menu System, IV Submenu - a command may lead to another menu Separator Bar - a horizontal bar used to separate groups of commands

MainMenu Control When used, the MainMenu control appears in the component tray (at the bottom of the Design Window) It is composed of MenuItem Objects, such as: Menu Name Menu Command Separator Bar Sub-Menu Command

MenuItem Names Should begin with "mnu" Then by convention are spelled, specifying their hierarchical position: mnuFile mnuFileSave mnuFilePrint

MenuItem Text Properties The text property is the text that appears on the menu Plus if there is a access key, it is preceded with an ampersand, e.g. Object Name Text Property mnuFile &File mnuFileSave &Save mnuFileExit E&xit

Menu Designer The Menu Designer speeds creation of menus with a fill in the box with text scheme: Enter the next menu name Enter first command in the File menu

Shortcut Keys These are the key shortcuts that get one directly to the command action without going through the menu system (e.g., CTRL-C for Edit/Copy) These are set via the Shortcut Property of each menu item

Disabled MenuItem Objects The status of a menu item (enabled vs. disabled) is controlled by the Enabled property: True is Enabled mnuEditPaste.Enabled = True

Adding Separator Bars Either make the menu item’s Text property equal to "-" (hyphen) Or right-click an existing menu item and select Insert Separator (it will be inserted above the menu item)

Inserting, Deleting, Rearranging Menu Items To Insert a new menu item above an existing one, right-click to use the context sensitive menu To Insert a new item at the end, use the Menu Designer To Delete a menu item, right-click/Delete To Rearrange menu items, click and drag them in the Menu Designer

Standard Menu Items In general follow the conventions that the majority of application menu systems use Specifically: 'File' is the leftmost menu item The File menu has an 'Exit' command 'Help' is the rightmost menu item The Help menu has an 'About' command

Context Menus To establish a pop-up menu when a control is right-clicked: Add the ContextMenu control to the component tray Build the menu system with the Menu Designer Add a Click Event procedure Then associate the menu with the control by setting the control's ContextMenu property to the established menu