Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 13 Additional Topics in Visual Basic

Similar presentations


Presentation on theme: "Chapter 13 Additional Topics in Visual Basic"— Presentation transcript:

1 Chapter 13 Additional Topics in Visual Basic
Programming In Visual Basic .NET

2 Advanced Validation Techniques
.NET ErrorProvider components Share some characteristics with Web validation controls Set MaxLength and/or CharacterCasing properties of text boxes Perform field-level validation using Validating event of input controls © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

3 The ErrorProvider Component
ErrorProvider component causes an error indication to appear next to the field in error Generally, one ErrorProvider can be used to validate all controls on a form 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) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

4 ErrorProvider.SetError Method
General Form Examples ErrorProviderObject.SetError(ControlName, MessageString) ErrorProvider1.SetError(quantityTextBox, "Quantity must be numeric.") ErrorProvider1.SetError(creditCardTextBox, "Required field.") © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

5 The MaxLength and CharacterCasing Properties
Helps user to enter correct input data MaxLength property Set maximum number of characters that can be entered, beeps and holds insertion point to indicate error CharacterCasing property Converts each character entered to Normal, Upper or Lower case (default is Normal) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

6 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

7 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

8 Multiple Document Interface
SDI = Single document interface All we have created thus far Each form in the project acts independently from the other forms (such as Splash form) MDI = Multiple document interface An example of an MDI application is Word Word has a parent form (the main window) and child forms (each document window) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

9 Multiple-Document Interface (continued)
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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. 4

10 MDI Application Forms © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

11 Creating an MDI Project
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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. 5

12 Child Form Code Example
Private Sub displayChildOneMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ displayChildOneMenuItem.Click ' Display Child One form. Dim childOneForm As New childOneForm( ) childOneForm.MdiParent = Me childOneForm.Show( ) End Sub © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

13 Creating an MDI Project (continued)
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) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

14 MDI Child Title Bar Example
' Module-level declarations. Dim childOneCountInteger As Integer Private Sub displayChildOneMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ displayChildOneMenuItem.Click ' Display Child One form. Dim childOneForm As New childOneForm childOneForm.MdiParent = Me childOneCountInteger += 1 childOneForm.Text = "ChildOne Document " _ & childOneCountInteger.ToString( ) childOneForm.Show( ) End Sub © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

15 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

16 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) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

17 Toolbars and Status Bars
Enhance usability of programs A toolbar requires a toolbar control and an image list component Toolbars are an easy shortcut for menu items Image list holds the graphics that appear on toolbar buttons Status bars appear at bottom of screen and display information for the user © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

18 Image Lists Toolbar control requires its images to be stored in an image list Add an ImageList component to the form Locate the Images property, click the Builder (ellipses) button to open the Image Collection Editor Click on the Add button to add images An index is automatically assigned to each image in the collection Use the index to assign the pictures to the toolbar buttons © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

19 Image Collection Editor
Image index © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

20 Toolbars Place the ToolBar object on the form
Assign the image list component for the form to the ImageList property of the toolbar Add buttons to the toolbar using the ToolBarButton Collection Editor Set properties for new buttons in the right pane of the editor A Toolbar has a single ButtonClick event, use the event arguments to determine which button was clicked © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

21 ToolBarButton Collection Editor
Contains two Buttons Assigning the Image for the Button Face © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

22 Coding for the Toolbar The toolbar has a single ButtonClick event that occurs when the user clicks any of the buttons Use the event arguments to determine which button was clicked Each button has an Index Example ToolBar1.Buttons.IndexOf(e.Button) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. 20

23 Toolbar Code Example Private Sub parentToolbar_ButtonClick(ByVal sender As _ System.Object, ByVal e As _ System.Windows.Forms.ToolbarButtonClickEventArgs) _ Handles parentToolbar.ButtonClick ' Execute appropriate procedure for button clicked. Select Case parentToolbar.Button.IndexOf(e.Button) Case 0 displayChildOneMenuItem_Click(sender, e) Case 1 displayChildTwoMenuItem_Click(sender, e) End Select End Sub © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

24 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 StatusBarPanel objects to the Status Bar © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

25 Status Bars (continued)
ShowPanels property False by default, only displays Text property of Status Bar Set to True to show Panels Panels Collection Click Add button in the StatusBarPanel Collection Editor to add a panel Set Panel properties in the right pane of Editor window © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

26 StatusBarPanel Collection Editor
Contains two Panels © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

27 Assigning Values to Panels
Assign values to the Text property at run time Examples dateStatusBarPanel.Text = Now.ToShortDateString( ) timeStatusBarPanel.Text = Now.ToLongTimeString( ) informationStatusBarPanel.Text = "It’s very late." © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

28 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 Generally set initial values in Form_load event and use a Timer component to update the time © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

29 Displaying the Date and Time (continued)
DateTime methods ToShortDateString ToLongDateString ToShortTimeString ToLongTimeString Actual display depends on the user's local system settings. © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

31 Calendar Controls DateTimePicker MonthCalendar
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

32 DateTimePicker Control
Value Property Contains the date Initially set to current date User can select a date or you can assign a date value to the property ValueChanged Event Allows use of all the properties of the system time on the Value property of the control © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

33 Crystal Reports Gallery contains "experts" for guidance in creating standard reports, forms and mailing labels May use an existing report or generate a new one Publish reports on Windows Forms or on Web Forms Note: Visual Basic .NET Standard Edition does not include Crystal Reports. © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

34 Create and Display a Report
Add a Report Designer Design the Report Template which includes Settings for connection to the database Layout of the report Add a CrystalReportViewer control to a form Connect the control to the template © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

35 Adding a Report Designer
Select Project menu, Add New Item Choose Crystal Report icon Name the report Choose type of report Using the Report Expert (opens a wizard) As a Blank Report From an Existing Report © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

36 Add New Crystal Report Item
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

37 Crystal Report Gallery
Often the easiest way to create a report © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

38 Standard Report Expert Wizard
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

39 Standard Report Expert Wizard – Select Table
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

40 Standard Report Expert Wizard - Select Fields
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

41 Display the Report Add a CrystalReportViewer control to the form
ReportSource Property Set to Report file name using Browse option Anchor Property Set for all four edges to allow control to resize, if the form is resized © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

42 The Report Designer Two new toolbars Field Explorer window
Use to add new fields to report Separate section in toolbox Use items to add elements such as lines, boxes or text not bound to a data field Template contains several bands for information (see Figure on next slide) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

43 Crystal Reports Layout in Report Designer
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

44 The Report Designer (continued)
Report Header Information which appears on only the first page of a multipage report Page Header Information which appears at top of each page Generally, report title and column headings Details Section Data for body of report Fields which appear on each line of report (each record) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

45 The Report Designer (continued)
Report Footer Information which appears once at the end of the report Page Footer Information which appears at the bottom of each page © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

46 Modifying Report Design
Move, resize and reformat fields in the designer Resize by using sizing handles Drag the field control to move it To reformat a field, right-click and select Format from the shortcut menu Select Report Expert from context menu to change the report design Select Style Expert to choose a new style © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

47 Adding a Report to a Web Form
Use the CrystalReportsViewer control from the Web Forms section of the toolbox Web version does not have printer options Set the ReportSource property in the Web Form’s Page_Load event © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

48 Moving a Crystal Reports Project
Change the data source for the report template Browse to current location of database file Change ReportSource property of the CyrstalReportViewer control Browse to locate project’s current folder © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.


Download ppt "Chapter 13 Additional Topics in Visual Basic"

Similar presentations


Ads by Google