10-1 Chapter 10 Security, Menus, Files, and Graphics.

Slides:



Advertisements
Similar presentations
Using Macros and Visual Basic for Applications (VBA) with Excel
Advertisements

Tutorial 8: Developing an Excel Application
Chapter 5: Database Forms and Reports
Lesson 17: Configuring Security Policies
Dialog Boxes and Menus. Menus Menu Bar Contains menus which drop down to display list of menu items Each item has a name and text property Each item has.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard.
Chapter 13: Advanced GUI and Graphics
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)
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Lesson 9: Fine-Tuning Your Workflow Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
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
Lesson 10: Adding Flash, Video, and Sound Content Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver.
Lesson 11: Maximizing Site Design Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
9-1 Chapter 9 Working with Databases in VB.NET. 9-2 Learning Objectives Understand how databases are used to store business data and how they differ from.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
3-1 Chapter 3 Variables, Assignment Statements, and Arithmetic.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
8-1 Chapter 8 Using User-Defined Data Types and Object Oriented Programming.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
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.
3 - 1 Chapter 3: Basic Excel Skills Management Science: The Art of Modeling With Spreadsheets, 2e PowerPoint Slides Prepared By: Alan Olinsky Bryant University.
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.
Lesson 12: Working with Code-editing Features Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
© Paradigm Publishing Inc. MICROSOFT WINDOWS XP MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
4 - 1 Chapter 4: Advanced Excel Skills Management Science: The Art of Modeling with Spreadsheets, 3e S.G. Powell K.R. Baker © John Wiley and Sons, Inc.
Slide 1-1 Chapter 1 Terms Information Systems Overview Introduction to Information Systems Judith C. Simon.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lesson 3: Migrating and Configuring User Data
Lesson 23: Configure File Recovery
Lesson 12: Configuring Remote Management
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
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.
Lesson 14: Adding Interactivity with the Spry Framework Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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.
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
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 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
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.
2-1 Chapter 2 Using VB.NET to Create a First Solution.
Chapter 1: An Introduction to Visual Basic .NET
Excel Tutorial 8 Developing an Excel Application
An Introduction to Programming and VB.NET
Presentation transcript:

10-1 Chapter 10 Security, Menus, Files, and Graphics

10-2 Learning Objectives Require a password to protect the information system from unauthorized access. Create a menu for a project using the MainMenu control and add code to the menu items to execute actions when an item is selected. Work with direct access data files

10-3 Learning Objectives (continued) Add and use the SaveFileDialog and OpenFileDialog controls to save and open files. Use graphics objects in your projects to draw figures on a form. Use graphics objects to add print and print preview capabilities to a project. Add the MS Chart control to the Toolbox and then to a form to use in charting data.

10-4 Using Passwords for Security (1/2) Add a password form to project – Add a dialog box form Set the FormBorderStyle property to FixedSingle Set the ControlBox property to False – Make that form the startup object – Use the password TextBox Tag property to set the password at design time – Set the PasswordChar property of the TextBox so that the password does not get displayed as it is typed in Tpically use * as the PasswordChar

10-5 Using Passwords for Security (2/2) Set the AcceptButton property of the form Set the CancelButton property of the form Add code to the form: – If AcceptButton is pushed Test the password entered against value of Tag If the same, hide dialog box and display application Otherwise display some message box to try again – If CancelButton is pushed Quit

10-6 Password Form

10-7 Step-by-step 10-1: Adding Password Security Demo

10-8 Menus and design Examine menus of known application Try to maintain a Common User Interface – Use a menu hierarchy the user is used to – Arrows indicate that a submenu will be displayed – Ellipsis (…) indicate that a dialog box will appear – Use shortcut keys so that the menu can be used directly from the keyboard

10-9 More menu design Keep main menus similar to the menus that we see in other Windows programs Group together related commands under a main menu heading that reflects the overall relationship of those commands Use unique menus when necessary but try to keep their use to a minimum. Use common elements to give the user an idea of what will happen when a menu option is selected Use common elements to show the user what alternatives exist for accessing the command on toolbars or from the keyboard.

10-10 The MainMenu control Drag a MainMenu control to your project It gets displayed in the component tray Type the menu captions directly on the form

10-11 Menu creation To add a separator line – Type a dash (-) as the menu text – Right click and choose New Separator To add a submenu – Type a caption to the right of the menu

10-12 Menu item properties

10-13 Adding code to menu item Double click the menu item An editor window appears with the right event stub Type in the code corresponding to the selection of that menu item

10-14 Converting event procedure from button click to menu click 1. Open the Code window by double-clicking the button for which the code is to be transferred. 2. Use the mouse to highlight the code for that event procedure [do not include the first statement (starting with “Sub”) and the last (End Sub) statements]. 3. Cut the code using the Edit|Cut menu option (use Ctrl-x as a shortcut for this operation) and delete the first and last statements of the empty event procedure. 4. Open the Code window for the corresponding submenu item Click event by clicking it once or by just changing to the menu item in the Code window. 5. Paste the code into the submenu item Click event procedure using the Edit|Paste menu option (use Ctrl-v as a shortcut for this operation). 6. Delete the button control from the form.

10-15 Step-by-step 10-2: Adding Menus to a VB.NET Project Demo

10-16 Using Direct Access Files Direct access file: Data file in which data are assumed to be stored as fixed length records Similar to sequential access files – Can be read and written directly from VB.Net Similar to database files – Data are stored as records – Data can be accessed directly

10-17 Depiction of direct access file

10-18 How to access data The key parameter: the record number – Identifies the record uniquely The record representation – Use a named Structure with elements of the right types – Need to be able to declare “fixed-length” strings Public Var i a bl e Name As String n is the length of the string

10-19 Structure example Structure EmpRecord Public strFName As String Public strLName As String Public strSSNum As String Public strPhone As String Public strPaytype As String Public decPayRate As Decimal End Structure

10-20 Opening a Direct Access File: FileOpen parameters

10-21 File Access Commands FilePut – FilePut(file number, variable name, record number) FileGet – FileGet(file number, variable name, record number) FileClose

10-22 Writing Data to Direct Access File intFileNum = FreeFile() FileOpen(intFileNum, strFileName, _ OpenMode.Random, _ OpenAccess.ReadWrite, _ OpenShare.Shared, Len(udtEmp)) ‘For-Next loop to write records to file For intCurrent = 0 To intEmpCntr - 1 FilePut(intFileNum, udtEmployees(intCurrent), intCurrent + 1) Next FileClose(intFileNum)

10-23 Reading Data from Direct Access File intFileNum = FreeFile() FileOpen(intFileNum, _ strFileName, _ OpenMode.Random, _ OpenAccess.ReadWrite, _ OpenShare.Shared, Len(udtEmp)) ‘For-Next loop to read records from file For intCurrent = 0 To intEmpCntr - 1 FileGet(intFileNum, udtEmployees(intCurrent), intCurrent + 1) Next FileClose(intFileNum)

10-24 Step-by-Step 10-4: Direct Access Files Demo

10-25 Using File Dialog Boxes Two controls with obvious purposes – OpenFileDialog – SaveFileDialog Common method and properties – ShowDialog(): displays the dialog box – Filter: gets or sets the file name filter string OSD.Filter=“All Files (*.*)|*.*|Text Files (*.txt)|*.txt” – FilterIndex=gets or sets the index of current filter OSD.FilterIndex=1 ‘Text Files (*.txt) is current filter

10-26 More on File Dialog Boxes You do not need to instantiate the objects Simply drag the control on the project You may want to change the name The most important property – FileName: gets or sets the file name selected

10-27 Typical use of File Dialog Box Set the filter and the filter index Call ShowDialog() method to display the dialog box Interact with dialog box to select of type in file name Dismiss the dialog by clicking the Open or Save or Cancel buttton Read the FileName property if anything but the Cancel button was selected Take action corresponding to the file name chosen

10-28 Checking for Errors: Using the FileInfo object FileInfo object is part of the Syste.IO namespace Typical use: – Import System.IO – Dim objFI As New FileInfo(strFileName) – If objFI.Exists Then ’check for existence of file – ……

10-29 More on FileInfo object CopyTo: Allows to copy to another file name Create: creates a file Delete: permanently delete a file Directory: gets an instance of the parent directory Extension: the extension part of the file name FullName: full path to the file or directory Length: the size of the file Name: the name of the file

10-30 Step-by-step 10-4: Using File Dialog Boxes Demo

10-31 Working with Graphics To draw graphics on forms, use GDI+ – Graphics Design Interface + Most tools are in the System.Drawing namespace Steps to create graphics on a control (form or other) in VB.Net – Create a graphics object – Use the graphics object to draw Lines Shapes Text Images

10-32 Main Graphics Objects Pen – Used to draw lines or curves Properties – Alignment – Color – PenType – Width Brush – Used to fill the interior of shapes Types of Brushes – SolidBrush – TextureBrush – Drawing 2D namespace HatchBrush LinearGradientBrush PathGradientBrush

10-33.Net Graphics Coordinate System: Coordinates are in pixels

10-34 The Panel Control Can be used to group items on a form Can be used to draw on it Call the CreateGraphics method – Returns a graphics object on which to draw Other controls with CreateGraphics method – Form – PictureBox – Button

10-35 Steps to draw on an object Obtain a Graphics object (call CreateGraphics method) If necessary – Create a Pen object – Create a Brush object Call methods of the Graphics object and pass the Pen or the Brush as parameter as needed – DrawRectangle – Clear – FillEllipse – DrawPolygon – FillPolygon

10-36 Step-by-step 10-4: Experimenting with Graphics Demo

10-37 More methods of the Graphics Class

10-38 Printing Use the PrintDocument object – Available from the System.Drawing namespace – Imports System.Drawing.Printing PrintDocument can raise PrintPage event – Raised whenever the Print method is called – Write code to format the printed document in the PrintPage event procedure

10-39 Steps to use PrintDocument 1. Create the item that we want to print. 2. Set the location on the document where it should be printed. 3. Select style, font, color, etc. of the item that you want to print. 4. Use the appropriate method to draw the item on the PrintDocument object.

10-40 Code to Specify the Format of the Print Document (1/3) Private Sub objPrintDocument_Print(ByVal sender As Object, _ ByVal e As PrintPageEventArgs) Dim sngX As Single Dim sngY As Single Dim sngLeftMargin As Single = e.MarginBounds.Left Dim sngRightMargin As Single = e.MarginBounds.Right Dim sngTopMargin As Single = e.MarginBounds.Top Dim objTitleFont As New Font("Courier New", 14, FontStyle.Bold) Dim objHeadingFont As New Font("Courier New", 12, FontStyle.Bold) Dim objRecordFont As New Font("Courier New", 12) Dim objBrush As SolidBrush = New SolidBrush(Color.Black) Dim objpen As Pen = New Pen(Color.Black) Dim strLine, strName As String, intCounter As Integer strLine = "Employees"

10-41 Code to Specify the Format of the Print Document (2/3) sngX = sngLeftMargin + 10 sngY = sngTopMargin + 5 e.Graphics.DrawString(strLine, objTitleFont, objBrush, sngX, sngY) strLine = "Name" & Space(26) ' write column headings strLine = strLine & "Phone" & Space(10) strLine = strLine & "Pay Type" sngY = sngY + 34 e.Graphics.DrawString( strLine, objHeadingFont, objBrush, sngX, sngY) sngY = sngY + 24 e.Graphics.DrawLine(objpen, sngX, sngY, sngRightMargin - 10, sngY)

10-42 Code to Specify the Format of the Print Document (3/3) For intCounter = 0 To intEmpCntr - 1 ' print records strName = Trim(udtEmployees(intCounter).strFName) & " “ & _ Trim(udtEmployees(intCounter).strLName) strLine = Spacer(strName, 30) strLine = strLine & Spacer(Trim(udtEmployees(intCounter).strPhone), 15) & Chr(9) strLine = strLine & udtEmployees(intCounter).strPaytype & Chr(9) sngY = sngY + 24 e.Graphics.DrawString(strLine, objRecordFont, objBrush, sngX, sngY) Next intCounter sngY = sngY + 36 ’ print total employees strLine = "Number of Employees = " & CStr(intEmpCntr) e.Graphics.DrawString(strLine, objHeadingFont, objBrush, sngX, sngY) End Sub

10-43 AddHandler: Dynamic Event Dispatch You can use a generic procedure (with the right paramters list) to be executed when an event is raised Use the AddHandler statement – AddHandler ObjectName.Event, AddressOf ProcedureName Allows to use the same code for – Printing to the printer – Printing to a PrintPreviewDialog control

10-44 Code for Printing the Document Private Sub mnuFilePrint_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnuFilePrint.Click Dim objPrintDocument As New PrintDocument() AddHandler objPrintDocument.PrintPage, AddressOf objPrintDocument_Print If PrinterSettings.InstalledPrinters.Count = 0 Then MessageBox.Show("No printers are currently installed", _ "Print Error", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information) Exit Sub End If objPrintDocument.Print() End Sub

10-45 Print Preview Use the PrintPreviewDialog control Set the UseAntiAlias property to True When print preview is requested – Set the Document property of the control to the PrintDocument object with the correct PrintPage event – Cal the ShowDialog to display the preview control

10-46 Code for Previewing the Document Private Sub mnuFilePrintPreview_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles _ mnuFilePrintPreview.Click Dim objPrintDocument As New PrintDocument() AddHandler objPrintDocument.PrintPage, AddressOf objPrintDocument_Print If PrinterSettings.InstalledPrinters.Count = 0 Then MessageBox.Show("No printers are currently installed", "Print Error", _ MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If dlgPreview.document = objPrintDocument dlgPreview.ShowDialog() End Sub

10-47 Step-by-step 10-5: Adding Print and Print Preview Demo

10-48 Adding Chart Control to Toolbox Make your form active Right-Click the Windows Forms tab Click Customize Toolbox Select the COM component tab Check Microsoft Chart Control 6.0

10-49 Setting Chart Properties Use the properties window as for any other control OR Right click on the control, select “Properties” and use the dialog box that pops up

10-50 Step-by-step 10-5: Working with the Chart Control Demo

10-51 Copyright 2004 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in section 117 of the 1976 United States Copyright Act without express permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages caused by the use of these programs or from the use of the information herein