Lesson 3 — Menus, MDIs, and Simple Loops Microsoft Visual Basic.NET, Introduction to Programming.

Slides:



Advertisements
Similar presentations
Prof. Yitzchak Rosenthal
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Using Macros and Visual Basic for Applications (VBA) with Excel
Tutorial 8: Developing an Excel Application
Microsoft Word 2010 Lesson 1: Introduction to Word.
© by Pearson Education, Inc. All Rights Reserved.
Automating Tasks With Macros
MENUS AND THE MENU EDITOR Elements of a Menu Menu bar Menu title Separator bar Menu items.
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.
Key Applications Module Lesson 12 — Word Essentials
Conversational Computers
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
© Ms. Masihi.  The Dreamweaver Welcome Screen first opens when you start Dreamweaver.  This screen gives you quick access to previously opened files,
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
Multiple Forms, Standard Modules, And Menus
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 7 Move and Copy.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
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.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Productivity Programs Common Features and Commands.
Graphical User Interface Concepts - Part 2 Session 09 Mata kuliah: M0874 – Programming II Tahun: 2010.
Get up to speed Get to know the Ribbon When you first open Word 2007, you may be surprised by its new look. Most of the changes are in the Ribbon, the.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Key Applications Module Lesson 21 — Access Essentials
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Microsoft Office XP Illustrated Introductory, Enhanced Started with Windows 2000 Getting.
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Chapter Three The UNIX Editors.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Menus Menus provide groups of related commands for windows applications Menu, menu items, submenus A menu item that contains a submenu is considered to.
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.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
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.
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.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Today We Will Review: Operating Systems (Windows) (week 3 & 4) Starting up MS Windows Desktop and its contents Functions of the desktop components Brain.
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 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Key Applications Module Lesson 12 — Word Essentials Computer Literacy BASICS.
1 Word Lesson 2 Basic Editing Microsoft Office 2010 Introductory Pasewark & Pasewark.
Menu & Clipboard Menu Cut / Copy / Paste. Menus Created in the Menu Editor Can contain menu titles, menu items, separator bars, submenu titles, and submenu.
Visual Basic.NET Windows Programming
Chapter 1: An Introduction to Visual Basic 2015
1. Introduction to Visual Basic
Presentation transcript:

Lesson 3 — Menus, MDIs, and Simple Loops Microsoft Visual Basic.NET, Introduction to Programming

Objectives Design a menu bar with menus and submenus. Plan and document an application. Use MDI forms. Use For loops to write programs.

Vocabulary Access keys Cascade Definite loop Indefinite loop Loop MainMenu tool Multiple document interface (MDI) Separator bar Shortcut key Tile

Menus Menus are a common Windows tool that make it easy to access commonly used commands. It is not hard to imagine a Windows application with no menu bar: all of your applications to this point have used buttons. Menus are a more natural interface than buttons because they allow you to group related actions. Therefore, menus are an important part of most Windows applications. The menu bar is found at the top of the application window directly under the title bar. Visual Basic lets you create menus quickly and easily.

Planning a Menu To what commands and options do users need access? In what order should the commands and options appear? What forms are required? What information needs to be included on each form? From where will this information come? Do the forms need to transfer information elsewhere?

Basic Elements of a Menu Menus are made up of the menu bar, menu titles, menu commands, submenu titles, and submenu commands. Menu titles appear on the menu bar at the top of the form. When you click a menu title, its menu opens and displays a list of menu commands or submenu titles. Menu items usually have associated access keys that allow the user to quickly access them through the keyboard. Often, menu items also have shortcut key combinations that let the user execute the command without using the mouse.

Basic Conventions Start all menu titles and menu commands with a capital letter. File and Edit are usually the first menu titles on a menu bar, and Help is usually the last one. Use short, specific captions, preferably no more than two words each. Start the names of all menu items with the three ‑ letter prefix "mnu."

The MainMenu Tool

Did You Know? In the early days of computers, the industry almost died because of a lack of programmers. In the late 1950s and early 1960s, programmers used assembly language, which is the obscure code-like language one level above machine language, or binary. It quickly became apparent that if something did not happen to make programming easier, the industry was doomed. To fill this need, high ‑ level languages, more easily understood by humans than computers, were developed. The computers helped themselves interpret these new languages.

Creating a Menu in a Windows Application

Note There are a number of properties of the menu item shown in the Properties window: The Checked property, when True, displays a check mark in front of the menu item. This is often used to show that the menu item has already been selected. This property can be set to True or False by program code. The Enabled property, when False, displays the item grayed out, so the user cannot select it. The Visible property, when False, makes the menu item invisible to the user. The Text property reflects the text entered in the Type Here box on the form.

Menu Building in Progress

Tip To reorder a menu, click and drag the item to a new position. The other items will make room as you drag.

Access Keys You are probably familiar with access keys and shortcut keys. Access keys allow you to open a menu by pressing the Alt key and then the designated letter. Access keys also allow the user to access a menu command once the menu is open by continuing to hold the Alt key and pressing its designated letter.

Shortcuts Shortcut keys are different. They run a menu command immediately after the shortcut key sequence is pressed. Shortcut keys with which you may be familiar are Ctrl+C for Copy and Ctrl+V for Paste. You cannot assign a shortcut key to a menu title.

Step-by-Step 3.3 Select the Open entry by clicking it. Click again to edit the entry. Position the cursor with the arrows and key an ampersand in front of the word Open. This makes the letter O the special access key.

Step-by-Step 3.3 In the Properties window, click the Shortcut property. Click the list arrow to the right of the entry and select CtrlO from the list. This sets the shortcut for this menu command to Ctrl+O. With the shortcut set, the user can execute this command from the keyboard without using the mouse or the access keys to select and open the menu.

Menu Changes in Progress

Tip Remember to name your objects as you create them. Use short meaningful names that start with the correct prefix. For menu items, use the mnu prefix.

Adding Code to a Menu When a user clicks a menu control, a Click event occurs. All menu controls, with the exception of the separator bar, recognize the Click event. Coding for a menu Click event works the same as coding for any other event procedure. You open the Code window, choose the menu control from the Class Name box on the left, and enter the code between the Protected Sub and End Sub statements. Another way to open a menu item’s Code window is to double-click the menu item in the MainMenu tool.

Step-by-Step 3.4 'Change the color of the text in txtMenuTest to Black Dim NewColor As New Color() txtMenuTest.ForeColor = NewColor.Black() 'Check the Black submenu control mnuEditColorBlack.Checked = True 'Uncheck the Blue submenu control mnuEditColorBlue.Checked = False 'Uncheck the Red submenu control mnuEditColorRed.Checked = False

Step-by-Step 3.4 'Change the color of the text in txtMenuTest to Blue Dim NewColor As New Color() txtMenuTest.ForeColor = NewColor.Blue 'UnCheck the Black submenu control mnuEditColorBlack.Checked = False 'Check the Blue submenu control mnuEditColorBlue.Checked = True 'Uncheck the Red submenu control mnuEditColorRed.Checked = False

Step-by-Step 3.4 'Change the color of the text in txtMenuTest to Red Dim NewColor As New Color() txtMenuTest.ForeColor = NewColor.Red 'Uncheck the Black submenu control mnuEditColorBlack.Checked = False 'Uncheck the Blue submenu control mnuEditColorBlue.Checked = False 'Check the Red submenu control mnuEditColorRed.Checked = True

Running a Program Run the program by selecting Debug | Start Without Debugging or pressing Ctrl+F5.

Colors Visual Basic’s handling of colors is very convenient for the programmer. When you click the list arrow in the ForeColor property in the Properties window, you get to choose between three different color management systems: you may select a color from among System Colors, custom colors from a palette of colors, or one of many predefined Web colors.

Multiple Document Interface (MDI) The multiple document interface (MDI) is another common item found in Windows applications. The MDI allows you to create an application that has many forms that are contained within one main form. Applications like Microsoft Word, where you can open several different documents within the main Word program, are MDIs. The forms that make up an MDI (em-dee-eye) project are referred to as parent and child forms. The main application is referred to as the parent, and all of the forms contained within the application are called the children.

Parents and Children There can be only one MDI parent form per application. This cuts down on the possible confusion that could result from having more than one form in charge of the rest. You create an MDI parent form by setting the appropriate property of the form in the Properties window. When you create an MDI form, the Properties window refers to it specifically as an MDI form rather than just a form. To have the application recognize that the other forms are children of the MDI form, you set their MDIChild property to True.

Programming Skills A major problem that programmers run into is that they tend to design for their own use. It may seem obvious to you or another programmer how a program should process data and how a user accesses and enters that data. However, the end ‑ user typically does not have the same perspective. Therefore, when designing a program, it is essential that you plan for alternate approaches. Murphy's law here is, “If there is one thing that would crash a program, users will find it."

Creating an MDI Application In order to create an MDI application, you must create an MDI form. Creating an MDI form is similar to creating any other new form. You populate the form with controls from the Toolbox and build a menu. Then change the form’s IsMDIContainer property to True. After the MDI container or parent form is created, you create a template from which child forms are created. You add a second form to the project and populate it with controls from the Toolbox and provide a menu. This second form is the template used to create child forms while the application is running.

Me While the application is running, the parent form can be referred to by the name Me. This is a special variable in Visual Basic. Me holds the name of the form that is currently active. Thus, the Me takes different values depending on the active form.

Step-by-Step 3.5 'Create a new instance (copy) of Form2 Dim NewMDIChild As New Form2() 'Designate the Child form's parent NewMDIChild.MDIParent = Me 'Display the new form. NewMDIChild.Show()

Cascaded Child Forms

Child Forms Tiled Horizontally

Child Forms Tiled Vertically

Child Form Icons Arranged on the Parent Form

Step-by-Step 3.6 Form1.LayoutMDI(MDILayout.Cascade) Form1.LayoutMDI(MDILayout.TileHorizontal) Form1.LayoutMDI(MDILayout.TileVertical) Form1.LayoutMDI(MDILayout.ArrangeIcons)

Adding a Form A unique form is created in the design phase of the project. Even though you work with the form in the design phase, the form must be called into existence by program code. If the name of the added form is About.vb, the code to create a new instance of the form is Dim NewAbout As New About().

The New Form Once a new form is added, the Show method of the form is called to display it. The Hide method hides the form without unloading it from memory. If necessary, the form’s Unload method is used to unload the form from memory. Unlike the child forms that appear wholly contained within the parent form, the new form is displayed independently.

Simple Loops Executing the same statements over and over at almost inconceivable speeds is what makes computers so powerful. Visual Basic has a number of statements designed to control this repetition. The first is the For loop. A loop is any program statement that causes the repetition of a group of statements. This is called a definite loop because its starting value, the upper limit, and the number of repetitions is generally known before the loop begins.

For loop The syntax of the For loop is: For control variable = starting value To upper limit Step increment body of the loop Next An example is: For x = 1 To 100 Step 2 'The statements that make up the body of the loop go here. Next x

Examples For x = LowerLimit To 5 * LowerLimit … Next x For Item = 1 to 25 … Next Item

Examples For x = ‑ 5 To 5 Step 0.01 … Next x For Pounds = 8 to 24 Time = Pounds * 17 … Next Pounds

Backward Loops can count forward or backward. For x = 10 To 1 Step ‑ 1 … Next x

Important The value of the control variable should not be changed in the body of a For loop. The value is controlled by the For loop itself.

Step-by-Step 3.8 'Declare the necessary variables. Dim StartingValue, UpperLimit, Increment As Integer Dim ControlVariable As Integer Dim DirectCost, FixedCost, TotalCost As Decimal 'Collect information from the TextBoxes. DirectCost = txtDirectCost.Text.ToDecimal FixedCost = txtFixedCost.Text.ToDecimal

Step-by-Step 3.8 'Collect information from the user. StartingValue = CInt(InputBox("Enter the starting value:")) UpperLimit = CInt(InputBox("Enter the upper limit:")) Increment = CInt(InputBox("Enter the increment:")) For ControlVariable = StartingValue To UpperLimit Step Increment TotalCost = DirectCost * ControlVariable + FixedCost MessageBox.Show("The cost at " & ControlVariable.ToString _ & " items is:" & CrLf & TotalCost.ToString) Next ControlVariable

Communication Skills In creating and editing programs, you will often forget why you did things a certain way or why a particular "fix" was used. That is why it is essential that you document your programs with explanations and dates for later reference. You may have already noticed that you have been using internal comments. This helps later when revisions are made and when the final documentation is done.

Summary Menus make it easier for users to execute commands in their programs. The MainMenu tool makes creating professional ‑ looking menus easy. Shortcut keys and access keys help speed up access to commonly used menu commands. The multiple document interface is made up of one parent form that contains many child forms.

Summary Previously created forms can be added from other projects. The MDILayout method provides flexibility to the user to display child forms in different ways. The For statement is used to build definite loops that repeat statements a fixed number of times.