Chapter 14 Additional Topics in Visual Basic Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

14-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Tutorial 8: Developing an Excel Application
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
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
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
 Using Microsoft Expression Web you can: › Create Web pages and Web sites › Set what you site will look like as you design it › Add text, images, multimedia.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Visual Basic Chapter 1 Mr. Wangler.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
Getting Started with Expression Web 3
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
1 Lesson 6 Exploring Microsoft Office 2007 Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
INTRODUCTION TO FRONTPAGE. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features Features  Starting Front Page Starting Front Page  Components.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
IE 411/511: Visual Programming for Industrial Applications
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
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,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
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.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
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.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
VB.NET Additional Topics
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter Two Creating a First Project in Visual Basic.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
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.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Banner 6.x Fundamentals: Navigation and Forms. n Name n Organization n Title/function n Job responsibilities n SCT Banner Experience n Expectations Introductions.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
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.
Dive Into® Visual Basic 2010 Express
Chapter 1: An Introduction to Visual Basic 2015
1. Introduction to Visual Basic
Using Procedures and Exception Handling
Chapter 13 Additional Topics in Visual Basic
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

Chapter 14 Additional Topics in Visual Basic Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill

14-2 Objectives Validate user input in the Validating event and display messages using an ErrorProvider component. Use code snippets in the editor. Create a multiple document project with parent and child forms. Arrange the child forms vertically, horizontally, or cascaded. Add toolbars and status bars to your forms using tool strip and status strip controls. Use calendar controls and date functions. Display a Web page on a Windows form using a WebBrowser control. Capture and check an individual keypress from the user.

14-3 Advanced Validation Techniques ErrorProvider components Share some characteristics with Web validation controls. Useful controls include: Set MaxLength and/or CharacterCasing properties of text boxes Perform field-level validation using Validating event of input controls.

14-4 The ErrorProvider Component ErrorProvider component causes an error message to appear next to the field in error on the form rather than pop-up messages in message boxes. Generally, one ErrorProvider can be used to validate all controls on a form. Added to the component tray If data value is invalid, a blinking icon displays next to the field in error and a message displays in a pop-up (similar to a ToolTip).

14-5 ErrorProvider.SetError Method General Form Examples ErrorProviderObject.SetError(ControlName, MessageString) ErrorProvider1.SetError(QuantityTextBox, "Quantity must be numeric. " ) ErrorProvider1.SetError(CreditCardTextBox, " Required field. " )

14-6 The MaxLength and CharacterCasing Properties Helps user to enter correct input data MaxLength property Set smaximum number of characters that can be entered, and beeps and holds insertion point to indicate error CharacterCasing property Converts each character entered to Normal, Upper, or Lower case (default is Normal) 2 characters

14-7 Field-Level Validation Displays any error message as soon as the user attempts to leave a field with invalid data To accomplish field-level validation use Validating event CausesValidation property ErrorProvider components

14-8 Using the Validating Event and CausesValidation Property Validation event is best location for validation code. Use CancelEventsArgs argument to cancel the event and return focus to the control. Each control on a form has a CausesValidation property set to True by default. When focus passes from one control to another, the validating event occurs for the control just left. Set CausesValidation to False on a control such as Cancel or Exit to give the user a way to bypass the validation.

14-9 Capturing Keystrokes from the User Check for the key that the user entered in a control’s KeyDown, KeyPress, or KeyUp event procedure. These events occur in the order listed for most keyboard keys with the following exception: Keystrokes that ordinarily cause an action to occur, such as the Tab key or Enter key, generate only a KeyUp event. The e argument of the KeyPress event procedure is KeyPressEventArgs. Has a KeyChar property that holds the character pressed Also has Handled property which can be set to True—that the keystroke needs no further processing; the action effectively “throws away” the keystroke just entered.

14-10 Using the Masked Text Box for Validation Set the Mask property of a masked text box to any predefined masks, or users can write their own. Easiest way to create a new one is to modify one of the existing masks. --OR-- Follow the syntax rules of a regular expression. Predefined masks include date, time, phone number, Social Security number, and ZIP code format.

14-11 Code Snippets Small samples of code that can show users how to accomplish many programming tasks Snippet categories include: Collections, Data Types — defined by VB, Interacting with the Application, Maintaining Collections, File System-Processing Drives, Folders and Files, Math, Security, and VB language The above list varies depending upon the location on the insertion.

14-12 Sample Projects Visual Studio includes many sample projects (all editions except the Express Edition) that can be used to learn new techniques. From the Help menu, select Contents; expand the nodes for Development Tools and Languages/Visual Studio/Visual Basic to find the Samples node. The Quick Starts are another avenue for pursuing the study of VB. Provide tutorials with step-by-step introduction to many techniques and controls

14-13 Multiple Document Interface (1 of 2) SDI = Single document interface Each form in the project acts independently from the other forms. MDI = Multiple document interface An example of a MDI application is Word. Word has a parent form (the main window) and child forms (each document window).

14-14 Multiple-Document Interface (2 of 2) Child form always stays within boundaries of the parent window. Close the parent window and all child windows close automatically. Child form always appears inside parent’s area. Window menu displays list of open windows, allows movement from one active document to another.

14-15 MDI Application Forms The main form is the parent and the smaller forms are the child forms.

14-16 Creating an MDI Project (1 of 2) At design time designate a form as Parent. IsMdiContainer property = True At run time designate Child forms Before displaying the Child form, from the Parent set the Child's MdiParent property to the current (parent) form.

14-17 Creating an MDI Project ( 2 of 2) If multiple child windows are displayed, the title bar of each child should be unique. Solution Append a number to the title bar before displaying the form (like MS Word).

14-18 Child Form Code Example Private Sub ChildOneMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ ChildOneMenuItem.Click ' Display Child One form. Dim AChildOneForm As New childOneForm( ) AChildOneForm.MdiParent - Me AchildOneForm.Show( ) End Sub

14-19 MDI Child Title Bar Example ' Module-level declarations. Dim childOneCountInteger As Integer Private Sub ChildOneMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ ChildOneMenuItem.Click ' Display Child One form. Dim AChildOneForm As New childOneForm AchildOneForm.MdiParent = Me childOneCountInteger += 1 AchildOneForm.Text - "ChildOne Document " _ & childOneCountInteger.ToString( ) AchildOneForm.Show( ) End Sub

14-20 Adding a Window Menu Parent form should include a Window menu to List open Child forms (Set menu's MdiList property to True.) Allow the user to arrange multiple Child forms Allow the user to switch between windows

14-21 MenuStrip Control (1 of 2) After the menus are created for a MenuStrip control, the menus can be set to display a list of open child windows. Display the properties of the MenuStrip (not a menu item) in the Properties window. Drop down the list for the MidiWindowList Item property displaying all of the menu items that belong to the MenuStrip. Select WindowToolStripMenuItem. Arranging the windows requires additional code.

14-22 MenuStrip Control (2 of 2) Set the MdiWindowListItem property to make the Window menu display the list of open MDI child windows.

14-23 Layout Options Use an argument of the LayoutMdi method to set the type of layout. Examples Me.LayoutMdi(MdiLayout.TileHorizontal) Me.LayoutMdi(MdiLayout.TileVertical) Me.LayoutMdi(MdiLayout.Cascade)

14-24 Toolbars and Status Bars Enhance usability of programs A toolbar requires a ToolStrip control and the images in Resources to appear on the ToolStrip buttons. Toolbars are an easy shortcut for menu items. Images can be collected using the Items Collection Editor window. With the ToolStrip selected, Standard Items can be inserted such as New, Open, Save, Print buttons and pictures are automatically added; however, the code must be written for each button. Status bars appear at bottom of screen; display information for the user; require a StatusStrip control.

14-25 Toolbars Use the ToolStrip control to create a ToolStrip object (container) which holds several type of objects. Use the Items property and open the Items Collection Editor. In the ToolStrip’s Items Collection Editor, drop down the list of available types of objects.

14-26 Items Collection Editor Drop down list of available objects such as buttons.

14-27 Status Bars Usually located at the bottom of a form to display date, time, status of CapsLock or NumLock, error or informational messages Place the StatusBar control on the form. Add a StatusStrip control. Add ToolStripStatusLabel objects to the StatusStrip. Like ToolStrips, the easiest way to add items to the StatusStrip object is to select its items property in the Properties window to open the ItemsCollection Editor. Set where labels appear by setting the StatusStrip’s RightToLeft property.

14-28 Assigning Values to ToolStripStatusLabels Assign values to the Text property at run time. Examples DateToolStripStatusLabel.Text = Now.ToShortDateString( ) TimeToolStripStatusLabel.Text = Now.ToLongTimeString( ) InformationToolStripLabel.Text = "It’s very late."

14-29 Displaying the Date and Time Use the properties and methods of the DateTime structure to retrieve and format the current date and time. Now property holds system date and time in numeric format that can be used for calculations. Generally, set initial values in Form_load event and use a Timer component to update the time. DateTime methods ToShortDateString ToLongDateString ToShortTimeString ToLongTimeString

14-30 Some Helpful Date Controls Provide the ability to display calendars on your form. DateTimePicker Takes less screen space Displays only day and date unless user drops down the calendar MonthCalendar Displays calendar

14-31 DateTimePicker Control Value Property Contains the date Initially set to current date User can select a date or can assign a date value to the property.

14-32 Calendar Controls

14-33 Using Calendars — Example BirthdateDateTimePicker.Value = Convert.ToDateTime(BirthdateTextBox.Text)

14-34 Displaying Web Pages on a Windows Form The toolbox includes a WebBrowser control. Forms resemble a browser window in Internet Explorer. Use the control to display an HTML page, online or offline.

14-35 The WebBrowser Control Some useful properties, methods and events of the WebBrowser control are:

14-36 A WebBrowser Program

14-37 XML Data Files(1 of 5) XML is a platform-independent format that is not tied to a specific language or vendor. VB 2008 includes some new tools that make working with XML files easier than in the past. The Load method of an Xdocument can be used to read an XML file.

14-38 XML Data Files(2 of 5) XDocument.Load Method—General Forms Examples Dim Identifier = XDocument.Load(Filename) Dim Identifier As XDocument = XDocument.Load(Filename) Dim BookXDocument = XDocument.Load("books.xml") Private CustomerXDocument As XDocument = XDocument.Load("C:\Data\customers.xml") Dim InventoryDocument = XDocument.Load(CurDir() & "inventory.xml")

14-39 XML Data Files(3 of 5) Loading an XML File into an XElement Object XML file can also be loaded into an XElement object. The difference between Xdocument and Xelement is that the XDocument contains the information about the document from the top of the file, while the root node is the first item in an XElement object. Dim BookData = XElement.Load("books.xml")

14-40 XML Data Files(4 of 5) LINQ Queries The axes notation can be used on the In clause of LINQ as well as in the Select clause. LINQ offers many operators. Dim MyQuery = From book In BookData... _ Select book.Value 'Gets the price.

14-41 XML Data Files(5 of 5) LINQ to XML Program Example The program reads the books.xml file, uses a LINQ to XML query, and loads the resulting list of titles into a list box.

14-42 Windows Presentation Foundation(WPF) WPF provides the ability to create richer user interfaces for multiple platform development. The user interface in WPF applications uses XAML (pronounced “zammel”) code rather than HTML. XAML (Extensible Application Markup Language) is an XML-based language that is much more interactive than the traditional HTML. XBAP is used to refer to a XAML Browser Application that runs in an Internet browser.

14-43 WPF Interoperability Using WPF Interoperability, WPF controls can be used in a Windows Forms application Add an ElementHost control to a Windows Form to host WPF controls.

14-44 WPF Application Project Selection

14-45 WPF Project

14-46 WPF Project Development Interface design is similar to a Web Form WPF controls are similar to, but not identical to Windows controls. WPF creates a Window with a Title property, as opposed to a Form with a Text property See the step-by-step instructions for Ch14WpfHelloWorld for an introduction to WPF development.