Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.

Slides:



Advertisements
Similar presentations
Prof. Yitzchak Rosenthal
Advertisements

MS® PowerPoint.
Working with Intrinsic Controls and ActiveX Controls
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Using Macros and Visual Basic for Applications (VBA) with Excel
Working with Large Worksheets, Charting, and What-If Analysis
COMPREHENSIVE Windows Tutorial 3 Personalizing Your Windows Environment.
PowerPoint. Getting Started with PowerPoint Objectives Start PowerPoint and open presentations Explore toolbars and menus Use the Office Assistant Work.
Microsoft Excel 2010 Chapter 7
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Copyright 2007, Paradigm Publishing Inc. POWERPOINT 2007 CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Create Presentation Open, Save, Run, Print, Close,Delete.
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
110-C1 Chapter 2 of the text: _ text boxes, group boxes, check boxes, radio buttons, picture boxes _ defining access keys tab sequence setting the focus.
1 Excel Lesson 3 Organizing the Worksheet Microsoft Office 2010 Introductory Pasewark & Pasewark.
Controls General Discussion. VB Controls Visual Basic Controls A control is the generic name for any object placed on a form Controls may be images,
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 3 Working with Symbols and Interactivity.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 9 - VB 2008 by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control 9.2 Seven Elementary.
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Objects 9.4 Graphics.
R EVIEW Array ElementsBubble Sort Comparisons Shell Sort Comparisons ,75022,517.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Microsoft Word 2000 Presentation 5. Major Word Topics Columns Tables Lists.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
CIS 338: VB.NET Components Dr. Ralph D. Westfall April, 2011.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Programs 9.4 Graphics.
1. Chapter 4 Customizing Paragraphs 3 More Paragraph Changes Highlight a paragraph in Word by applying borders and shading. Sort paragraphs to control.
 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.
COMPREHENSIVE Access Tutorial 6 Using Form Tools and Creating Custom Forms.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
LINKS TO OBJECTIVES Multiple Worksheets Multiple Worksheets Move, Copy and Paste Cells Move, Copy and Paste Cells Split into Windows Freeze Panes Range.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
© 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 15 Advanced Tables.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
PowerPoint Practice Exercise 1.Save this file on your computer. 2.Open this file in PowerPoint 3.Edit each slide according to the instructions provided.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
Windows 95/NT/XP. What is Windows 95/NT/XP n A program that sets up an environment for you to work in on your computer, based on colorful pictures (icons)
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Controls. Common properties Height – Height of the control Left – Left of the control Width – width of a control Top - From the screen top Font – Foreground.
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.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
PowerPoint Chapter 1 Creating and Editing a Presentation with Clip Art Discovering Computers & Microsoft Office 2010.
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.
Chapter 8 Using Document Collaboration, Integration, and Charting Tools Microsoft Word 2013.
Windows Tutorial 3 Personalizing Your Windows Environment
Chapter 1: An Introduction to Visual Basic 2015
Building a User Interface with Forms
Chapter 9 – Additional Controls and Objects
Using Procedures and Exception Handling
Chapter 9 – Additional Controls and Objects
The Check Box Control Consists of a small square and a caption
Chapter#9: A Deeper Look In Controls
Chapter 9 – Additional Controls and Objects
The List Box Control Items can be placed into the list at design time or run time The Sorted property causes items in the list to be sorted automatically.
Additional Topics in VB.NET
Presentation transcript:

Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control The Combo Box Control The OpenFileDialog Control

Chapter 9 - VB.Net by Schneider2 The List Box Control Items can be placed into the list at design time or runtime The Sorted property causes items in the list to be sorted automatically If the Sorted property is set to True, then the following will place an item into the list in order and assign the index of its position to num: num = lstBox.Items.Add(str)

Chapter 9 - VB.Net by Schneider3 Useful Properties of the List Box For the total number of items in a list box: lstBox.Items.Count For the index number of the currently highlighted item: lstBox.SelectedIndex

Chapter 9 - VB.Net by Schneider4 More List Box Properties lstBox.Items() is the list of items in the list box. The value of the item with an index of "n" is: lstBox.Items(n) The data type of the elements in the lstBox.Items() array is Object. To put the first element of lstBox.Items in a text box: txtBox.Text = CStr(lstBox.Items(0))

Chapter 9 - VB.Net by Schneider5 Currently Highlighted Item in a List Boxes The currently highlighted item can be obtained by: lstBox.Items(lstBox.SelectedIndex) Or lstBox.Text

Chapter 9 - VB.Net by Schneider6 Removing Items from a List Box To delete an item at a given location: lstBox.Items.RemoveAt(n) To delete the first occurrence of an item: lstBox.Items.Remove(str) To remove everything from a list box: lstBox.Items.Clear()

Chapter 9 - VB.Net by Schneider7 List Box Events Three main types of events with list boxes: Click – if the user clicks on an item in the list box SelectedIndexChanged - if the user clicks on an item or uses the arrow keys to select it DoubleClick - if the user double-clicks on an item Click, DoubleClick, and SelectedIndexChanged events are triggered when the user double-clicks.

Chapter 9 - VB.Net by Schneider8 Example 1 Private Sub lstOxys_SelectedIndexChanged(...) Handles lstOxys.SelectedIndexChanged txtSelected.Text = CStr(lstOxys.SelectedItem) End Sub Private Sub btnAdd_Click(...) Handles btnAdd.Click Dim item As String item = InputBox("Item to Add:") lstOxys.Items.Add(item) End Sub Private Sub lstOxys_DoubleClick(...) Handles lstOxys.DoubleClick lstOxys.Items.RemoveAt(lstOxys.SelectedIndex) txtSelected.Clear() End Sub

Chapter 9 - VB.Net by Schneider9 Filling a List Box at Design Time 1.Select the Items property of the list box. 2.Click on the ellipses button on the right side of the Settings box. (A window titled String Collection Editor will be displayed.) 3.Type in the first item, and press Enter. 4.Repeat Step 3 for each of the other items. 5.When you are finished entering items, click on the OK button.

Chapter 9 - VB.Net by Schneider10 The Combo Box Control A list box combined with a text box The user has the option of selecting from a list or typing in something Three types of combo boxes in the DropDownStyle property: Simple DropDown DropDownList

Chapter 9 - VB.Net by Schneider11 Example 2 Private Sub btnDisplay_Click(...) Handles btnDisplay.Click txtDisplay.Text = cboTitle.Text & " " & txtName.Text End Sub

Chapter 9 - VB.Net by Schneider12 The OpenFileDialog Control Implements the standard File Open dialog box Normally the 37 th control in the Tool Box When you place the control on the form, it will not be visible The icon and default name will appear in the pane below the Main area

Chapter 9 - VB.Net by Schneider13 An Open File Dialog Box

Chapter 9 - VB.Net by Schneider14 Using the OpenFileDialog control To display the control: OpenFileDialog1.ShowDialog() After the Open button has been pressed, the file name selected and its complete filespec will be contained in the property: OpenFileDialog1.FileName

Chapter 9 - VB.Net by Schneider15 Example 3 Private Sub btnSelect_Click(...) Handles btnSelect.Click Dim textFile As String OpenFileDialog1.ShowDialog() textFile = OpenFileDialog1.FileName Dim sr As IO.StreamReader = IO.File.OpenText(textFile) lstOutput.Items.Clear() Do While sr.Peek <> -1 lstOutput.Items.Add(sr.ReadLine) Loop sr.Close() End Sub

Chapter 9 - VB.Net by Schneider Seven Elementary Controls The Group Box Control The Check Box Control The Radio Button Control The Timer Control The Picture Box Control The Horizontal and Vertical Scroll Bar Controls

Chapter 9 - VB.Net by Schneider17 The Group Box Control Group boxes are passive objects used to group other objects together When you drag a group box, the attached controls follow as a unit To attach a control to a group box, create the group box, then drag the control you want to attach into the group box

Chapter 9 - VB.Net by Schneider18 Group Box Example Text property of the group box Three attached controls: TextBox1 TextBox2 TextBox3

Chapter 9 - VB.Net by Schneider19 The Check Box Control Consists of a small square and a caption Presents the user with a Yes/No choice Checked property is True when the check box is checked and False when it is not CheckedChanged event is triggered when the user clicks on the check box

Chapter 9 - VB.Net by Schneider20 Example 1 Private Sub Tally(...) Handles chkDrugs.CheckedChanged, chkDental.CheckedChanged, chkVision.CheckedChanged, chkMedical.CheckChanged Dim sum As Double = 0 If chkDrugs.Checked Then sum += End If If chkDental.Checked Then sum += 9.68 End If If chkVision.Checked Then sum += 1.5 End If If chkMedical.Checked Then sum += End If txtTotal.Text = FormatCurrency(sum) End Sub

Chapter 9 - VB.Net by Schneider21 Example 1 output

Chapter 9 - VB.Net by Schneider22 The Radio Button Control Consists of a small circle with a caption (that is set by the Text property) Give the user a single choice from several options Clicking on one removes the selection from another Normally Radio Buttons are attached to a Group Box

Chapter 9 - VB.Net by Schneider23 Radio Button Properties To determine if the button is on or off radButton.Checked To turn a button on radButton.Checked = True

Chapter 9 - VB.Net by Schneider24 Example 2 Private Sub btnVote_Click(...) Handles btnVote.Click If radCandidate1.Checked Then txtVote.Text = "You voted for Kennedy." ElseIf radCandidate2.Checked Then txtVote.Text = "You voted for Nixon." Else txtVote.Text = "You voted for neither." End If End Sub

Chapter 9 - VB.Net by Schneider25 Example 2 output

Chapter 9 - VB.Net by Schneider26 The Timer Control Invisible during runtime Triggers an event after a specified period of time The Interval property specifies the time period – measured in milliseconds To begin timing, set the Enabled property to True To stop timing, set the Enabled property to False The event triggered each time Timer1.Interval elapses is called Timer1.Tick.

Chapter 9 - VB.Net by Schneider27 The Picture Box Control Designed to hold drawings and pictures To draw a blue rectangle with the upper left hand corner x pixels from the left of the picture box and y pixels from the top, with width w and height h: picBox.CreateGraphics. DrawRectangle(Pens.Blue, x, y, w, h)

Chapter 9 - VB.Net by Schneider28 Picture Box Containing a Red Circle picBox.CreateGraphics. DrawEllipse(Pens.Red, 35, 35, 70, 70)

Chapter 9 - VB.Net by Schneider29 Picture Box Properties A picture can be placed in a picture box control with the Image property. Prior to setting the Image property, set the SizeMode property. AutoSize will cause the picture box control to be resized to fit the picture. StretchImage will cause the picture to be resized to fit the picture box control.

Chapter 9 - VB.Net by Schneider30 Picture Box at Run Time A picture also can be assigned to a picture box control at run time: picBox.Image = Image.FromFile(filespec) The SizeMode property can be altered at run time with a statement such as picBox.SizeMode = PictureBoxSizeMode.AutoSize

Chapter 9 - VB.Net by Schneider31 The Horizontal and Vertical Scroll Bars

Chapter 9 - VB.Net by Schneider32 Scroll Bar Behavior When the user clicks on one of the arrow buttons, the scroll box moves a small amount toward that button. When the user clicks between the scroll box and one of the arrow buttons, the scroll box moves a large amount toward that button. The user can also move the scroll box by dragging it.

Chapter 9 - VB.Net by Schneider33 Scroll Bar Properties The main properties of a scroll bar control are Minimum Maximum Value SmallChange, LargeChange hsbBar.Value is a number between hsbBar.Minimum and hsbBar.Maximum

Chapter 9 - VB.Net by Schneider34 Scroll Bar Notes The setting for the Minimum property must be less than the setting for the Maximum property. The Minimum property determines the values for the left and top arrow buttons. The Maximum property determines the values for the right and bottom arrow buttons. The Scroll event is triggered whenever any part of the scroll bar is clicked.

Chapter 9 - VB.Net by Schneider Four Additional Objects The Clipboard Object The Random Class The MainMenu Control Multiple Forms

Chapter 9 - VB.Net by Schneider36 The Clipboard Object Used to copy information from one place to another Maintained by Windows so it can even be used with programs outside VB.NET A portion of memory that has no properties or events

Chapter 9 - VB.Net by Schneider37 Using the Clipboard Object To place something in the Clipboard: Clipboard.SetDataObject(str) To get something out of the Clipboard: Dim data As IDataObject = _ Clipboard.GetDataObject() str = CStr(data.GetData(DataFormats.Text)) To delete the contents of the Clipboard Clipboard.SetDataObject("")

Chapter 9 - VB.Net by Schneider38 The Random Class A random number generator declared with the statement: Dim randomNum As New Random() If m and n are whole numbers and m < n then the following generates a whole number between m and n (including m, but excluding n) randomNum.Next(m, n)

Chapter 9 - VB.Net by Schneider39 Example 1 Private Sub btnSelect_Click(...)Handles btnSelect.Click 'Display the winning lottery numbers Dim randomNum As New Random() Dim num1, num2, num3 As Integer num1 = randomNum.Next(0, 10) num2 = randomNum.Next(0, 10) num3 = randomNum.Next(0, 10) txtNumbers.Text = num1 & " " & num2 & " " & num3 End Sub

Chapter 9 - VB.Net by Schneider40 Example 1 Output

Chapter 9 - VB.Net by Schneider41 The Main Menu Control Top-level menu Second-level menu

Chapter 9 - VB.Net by Schneider42 Menu Events Each menu item responds to the Click event Click event is triggered by the mouse Alt + access key Shortcut key

Chapter 9 - VB.Net by Schneider43 Multiple Forms VB.NET programs can contain more than one form To add the new form select Windows Form from the Templates pane, optionally type in a name, and press the Open button.

Chapter 9 - VB.Net by Schneider44 Variables and Multiple Forms Local variables are declared with Dim Class-level variables are declared with Dim Variables declared with Public will be available to all forms in the program. When a Public variable is used in another form, it is referred to by an expression such as secondForm.variableName.