Apply Procedures to Develop Menus, List Box and Combo Box Objects

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Apply Procedures to Develop Menus,
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter 2 –Visual Basic, Controls, and Events
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Programming Based on Events
Group Boxes and Panels Arrange components on a GUI Buttons and etc. can be placed inside a group box or panel. All these buttons move together when the.
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
Chapter 2 –Visual Basic, Controls, and Events
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
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.
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”
3.2 VB.NET Events An Event Procedure Properties and Event Procedures of the Form Tab Order of Controls Exercises.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
1 Advanced Computer Programming Lab Calculator Project.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
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.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Unit 6 Repetition Processing Instructor: Brent Presley.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
IMS 3253: Forms, Controls, Properties, Events 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Program Elements Assignment.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
21/03/ Working with Controls Text and List Boxes.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
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.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Use TryParse to Validate User Input
Multiple Forms and Menus
Visual Basic Fundamental Concepts
Objective 7.04 Apply Built-in String Functions (3%)
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Objective 7.03 Apply Built-in Math Class Functions
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
Use TryParse to Validate User Input
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Repeating Program Instructions
Visual Basic..
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development and Programming using Visual Basic.net
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Project Design, Forms and Buttons
Visual C# - GUI and controls - 1
Brief description on how to navigate within this presentation (ppt)
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Apply Procedures to Develop Menus, List Box and Combo Box Objects Computer Programming I

Objective/Essential Standard Essential Standard 6.00 Apply tools to obtain and validate user input. Indicator 6.01 Apply procedures to develop menus, List Box and Combo Box objects (3%)

Adding a Menu

Why Add a Menu? Adding a menu increases the interactivity of your application. The menu allows the user to interface with your application. What menus can be added to your application form? In this course, we will add a MenuStrip to our form.

The MenuStrip Control Adds a menu bar to your form Use the prefix mnu when naming your menu Example: mnuMain Once you click the MenuStrip control, it doesn’t matter where you click on the form. It will automatically place the menu at the top.

The MenuStrip Control Note that when you add the MenuStrip, it puts an icon in the gray area at the bottom called the component tray.

The MenuStrip Control Select the MenuStrip control Select the (Name) property to change the name Use the prefix mnu

The MenuStrip Control Click in the text area of the MenuStrip control, type “Program”. Note this changes the text property and the name property of this menu entry in the Properties area. You can add additional menu entries at the same level or add submenu items.

The MenuStrip Control To add code to your menu item, go to your code view. Right Click  View Code View Menu  Code F7 Double Click the Menu Item In the Class Name List, select your menu object. In the Method Name List, select the appropriate method. In this case, we are selecting the Click event

The MenuStrip Control Type your code inside the Click event. For example if you wanted the application to close when Program is selected, type the following: Application.Exit() Note that an Autolist is provided as you type.

Form – Backcolor property The form has a new property called Backcolor. Backcolor – changes the color of the background of the form Ex: BackColor = Color.Blue The keywork Color. will generate a list of system colors to choose from.

Try It! Create a new application called menuExample. Save it in the folder as directed by your teacher. Add a MenuStrip control Properties: Name: mnuMenu Add an entry so that your form matches the image. Properties: Name: mnuChgClr Name: mnuChgBlu Name: mnuChgRed Name: mnuExit

Try It! Solution – Visual Basic Public Class Form1 Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Application.Exit() End Sub Private Sub BlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueToolStripMenuItem.Click Me.BackColor = Color.Blue Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedToolStripMenuItem.Click Me.BackColor = Color.Red End Class

ListBox & ComboBox

ListBox & ComboBox List boxes and combo boxes increase the interactivity of your application giving choices to the user. They allow the user to interface with your application. In this presentation we will look at how to add these new control objects to your application.

The ListBox Control The ListBox displays a list from which the user can select one or more items. If the list is longer than the list box, a scrollbar is automatically added.

The ListBox Control Properties (Name) The name of a ListBox should start with the prefix lst (This is the lowercase letter L, not a number 1.) Items Click in this property where it displays (Collection). A new dialog box called the String Collection Editor will appear. Type your list box items here. Be careful with your spelling. Make sure you hit the Enter key after the last item.

The ListBox Control Properties Text The text property returns the actual string value of the item. The item selected when running is placed inside the text property. Enabled The enabled property is set to true by default. If this property is set to false, the list box is not available for the user. Sorted The sorted property is set to false by default. If this property is set to true, your collection of items will be sorted ascending. Visible The visible property is set to true by default. If this property is set to false, the list box is not visible to the user.

Using The ListBox Control - Runtime SelectedIndex Property This property allows the programmer to compare what the user has selected in the list box with a value. The first item in the list box is at index position 0. If the user selects the first item in the list box, the SelectedIndex value will be 0, if the second item is selected, the SelectedIndex value is 1. If no item is selected, the SelectedIndex value is -1. This property is only available at runtime. Item SelectedIndex Value First Second 1 Third 2

Using The ListBox Control - Runtime SelectedItem Property This property allows the programmer to compare what the user has selected in the list box with the item itself as a string value. The comparison is exact, so your spelling, capitalization, and spacing matters. This property is only available at runtime. Item SelectedItem Value First Chocolate Second Strawberry Third Vanilla

Using The ListBox Control ListBox.SelectedIndexChanged & SelectedIndex You will use a SelectedIndexChanged event to compare either index values or the item to determine the list box item selected. 3

Pre 2010 Logic : Using The ListBox Control ListBox.SelectedIndexChanged & SelectedItem You will use a SelectedIndexChanged event to compare either index values or the item to determine the list box item selected. Your string must match the item exactly that is typed in the Collection.

Runtime Commands - ListBox Control During runtime, you can add, delete and clear all items from a ListBox using Items.Add, Items.Remove and Items.Clear. Me.lstFlavors.Items.Add(“Cherry”) ‘Adds Cherry to the lstFlavors collection Me.lstFlavors.Items.Remove(“Vanilla”) ‘Removes Vanilla from the lstFlavors collection Me.lstFlavors.Items.Clear() ‘Clears the entire list.

ListBox & ComboBox SelectedIndexChanged Just like you create a TextChanged event for a TextBox, you can create a SelectedIndexChanged event for a ListBox or ComboBox. You can use this event to clear the answer from a label. Private Sub lstChoice_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstChoice.SelectedIndexChanged Me.lblResult.Text = Nothing ’Clears Label End Sub

The ComboBox Control The ComboBox displays a list in a drop-down box. It is actually a combination of a textbox and a listbox. The top of the ComboBox allows the user to type input. The second part of the ComboBox displays a list of items from which the user can select. Textbox Listbox

The ComboBox Control Properties (Name) The name of a ComboBox should start with the prefix cbo Items Click in this property where it displays (Collection). A new dialog box called the String Collection Editor will appear. Type your items here. Be careful with your spelling. Make sure you hit the Enter key after the last item.

The ComboBox Control Properties Text The text property returns the actual string value of the item. Enabled The enabled property is set to true by default. If this property is set to false, the list box is not available for the user. Sorted The sorted property is set to false by default. If this property is set to true, your collection of items will be sorted ascending. Visible The visible property is set to true by default. If this property is set to false, the list box is not visible to the user.

Using ComboBox Control –Visual Studios 2010 Whether a value was keyed or an item selected, the text property will hold the value. Example: MessageBox.Show(Me.cboComboBox.Text) ’value typed or item selected is shown.

Using The ComboBox Control Prior to Visual Studios 2010, an If…Then…Else statement was needed to determine if a value was entered or an item selected. 2010 users can use the text property as shown in the previous example. Example: If Me.cboComboBox.SelectedIndex >= 0 Then MessageBox.Show(Me.cboComboBox.SelectedItem) ’item selected Else MessageBox.Show(Me.cboComboBox.Text) ’value typed End If

Try It! Create a new application called iceCreamExample Save it into the location as instructed by your teacher. Add the following controls. When the button Order is clicked, the order should be displayed in the lblOrder label. Control Name Text/Items Label lblFlavors Flavors ListBox lstFlavors Chocolate Strawberry Vanilla lblCone Cone/Cup ComboBox cboCome Cup Sugar Cone Waffle Cone lblOrder Empty

Try It! Solution Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click Dim Cone As String Dim Flavor As String ’ VB 2007 code – not needed in 2010 If (Me.cboCone.SelectedIndex >= 0) Then Cone = cboCone.SelectedItem 'Cone Selected Else : Cone = cboCone.Text 'Cone/Cup Typed Cone = cboCone.Text ‘VB 2010 code replaces red code above Flavor = lstFlavors.SelectedItem 'Flavor Selected lblOrder.Text = "You ordered: " & Flavor & " ice cream on/in a " & Cone End Sub

When to use a ComboBox vs. a ListBox Use a ComboBox when there is a list of suggested choices. A ListBox gives the user a list of choices whereas a ComboBox allows the user to enter input (the TextBox portion) in addition to providing options.

Conclusion This PowerPoint provided an overview of adding a menu in Visual Studio. For more information http://msdn.microsoft.com/en-us/library/ms171649.aspx http://msdn.microsoft.com/en-us/library/2chz8edb(v=VS.80).aspx