Teaching%20an%20Introductory%20Programming%20Class - PowerPoint PPT Presentation

View by Category
About This Presentation
Title:

Teaching%20an%20Introductory%20Programming%20Class

Description:

Anita C. Millspaugh. Professor, Computer Information Systems. Mt. San ... Locked controls have a dark border when selected. Command Buttons are now Buttons ... – PowerPoint PPT presentation

Number of Views:189
Avg rating:3.0/5.0
Slides: 103
Provided by: anitamil
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Teaching%20an%20Introductory%20Programming%20Class


1
Teaching an Introductory Programming Class
  • Using Visual Basic .NET

2
We are...
Anita C. Millspaugh Professor, Computer
Information Systems Mt. San Antonio
college Julia Case Bradley Professor Emeritus,
Computer Information Systems Mt. San Antonio
College Bradley/Millspaugh texts VB 4, VB 5,
VB 6, Advanced VB, Java and the new VB .NET
3
You
Teach Visual Basic 6? Are planning to teach
Visual Basic .NET? Have taught an OOP language
such as Java, SmallTalk, or C?
4
Our Goals for Today
  • Help you transition from VB 6 to VB .NET
  • Look at the differences between
  • Visual Basic 6 object based event driven
  • Visual Basic .NET object oriented
  • Introduce the new Visual Studio IDE
    (integrated development environment)
  • Show the changes to the language and the new
    features

5
Our Approach
  • This is an introductory programming course
  • Main topics
  • Program planning
  • Programming logic
  • Variables, constants, calculations, decisions,
    loops, data files
  • Language syntax
  • Coding standards
  • Testing and debugging
  • The VB .NET course still covers these topics,
    with OOP concepts embedded throughout.

6
What is the .NET Framework?
  • Platform for building and running applications
  • Designed for cross-platform compatibility
  • Common Language Runtime (CLR)
  • Share methods and objects from different
    languages
  • Many languages to choose from VB, C,
    COBOL, Fortran, J

7
The Biggest Change in VB .NET OOP
  • A new mind set
  • New keywords
  • Inherits
  • Overrides
  • Overloads
  • Terminology introduced in Chapter 1
  • Concepts covered in Chapter 6

8
The Second Biggest Change Web Forms
  • Programming for the Web vs. Windows
  • New set of controls
  • Client side vs. server side
  • Web page layout
  • Very simple projects presented in Chapter 9

9
The Third Biggest Change Data File Handling
  • Database uses ADO .NET (Chapter 10)
  • No Data control
  • Simple program is more difficult
  • Binding is more robust and likely to be used by
    real programmers
  • Must write code for navigation
  • Simple data files use streams (Chapter 11)

10
Chapter 1 Introduction Topics Covered
  • Objects, Methods, and Properties
  • The Visual Studio IDE
  • Planning a Project
  • Creating a Project
  • Labels and Buttons
  • Code
  • Syntax and Logic Errors
  • Help

11
Chapter 1 Changes
  • New IDE

12
Chapter 1 (continued)
  • Terminology VS IDE Solution
    Explorer Form Designer Editor window
  • Tabbed display is the default for the IDE
  • AutoHide toolbox can be pinned open

13
Chapter 1 (continued)
Push Pin
Tabbed Window
Locked Control
14
Chapter 1 (continued)
  • A solution can contain multiple projects
  • Forms, classes, and code modules have a .vb
    extension
  • The IDE automatically creates a folder for the
    project

15
Chapter 1 (continued)
  • Form Designer
  • Similar to VB 6
  • Double-Click a control in the toolbox
  • New default-sized control
  • Appears on top of a selected control
  • Top-left of the form if no control is selected
  • Locked controls have a dark border when
    selected
  • Command Buttons are now Buttons
  • Use btn for prefix
  • No more Caption property now it is Text

16
Chapter 1 (continued)
  • The Editor window (formerly the Code window)
  • Lots more IntelliSense help can be confusing
  • Declarations section replaces General
    Declarations
  • Class List and Method List
  • - Selecting the object and event is somewhat
    different
  • Collapsible Regions in code

17
Chapter 1 (continued)
Tabs
Method List
Class List
Collapsed Region
Collapsed Procedure
18
Chapter 1 (continued)
  • Complications
  • Changing the name of the form requires the
    projects startup object to be changed
  • PrintForm is no longer supported
  • IDE Print does not offer Form Image or Form
    Text
  • No edit-and-continue execution
  • Must restart (recompile) if edits are made
    during break time

19
Chapter 1 (continued)
  • Form and controls no longer have Caption property
  • Forms, buttons, labels all use the Text property
  • The Alignment property becomes TextAlign
  • The maximum length of identifiers is 16,383
  • All new Help MSDN
  • Redesigned Object Browser
  • Me.Close()

20
Chapter 2 More Controls Topics Covered
  • Check Boxes
  • Radio Buttons
  • Group Boxes
  • Picture Boxes
  • Designing an Interface
  • Setting the Tab Order
  • Setting up keyboard access keys (shortcuts)

21
Chapter 2 Changes
  • No more Image control, Line control, or Shape
    control
  • Use PictureBox for graphics Label for lines
  • OptionButton becomes RadioButton
  • Frame becomes GroupBox
  • AcceptButton and CancelButton are properties of
    the form
  • Set the forms StartPosition property no more
    Form Layout Window

22
Chapter 2 (continued)
  • PictureBox controls
  • Use Image property to hold a graphic
  • Set SizeMode property to StretchImage
    replaces Stretch property of Images
  • CheckBox controls
  • Value property becomes the Checked property
    (Boolean)
  • Its event is CheckChanged
  • Great new method for setting tab order

23
Chapter 2 (continued)
View / Tab Order
24
Chapter 2 (continued)
  • New component tray holds non-visible controls
  • To add ToolTips, add a ToolTip control to the
    component tray
  • New ToolTip on ToolTip1 property is added to the
    form and all controls
  • Text boxes have a Clear method
  • txtName.Clear()
  • txtName.Text
  • Focus method replaces SetFocus
  • txtName.Focus()

25
Chapter 2 (continued)
  • Many colors available through the Color class
  • lblMessage.ForeColor Color.Blue
  • Color.Red
  • Color.Yellow
  • Color.Aquamarine
  • Color.Bisque
  • Color.Chocolate
  • Color.Cadetblue
  • and dozens more

26
Chapter 3 Variables, Constants and
Calculations Topics Covered
  • Variables, constants, calculations
  • Data types
  • Converting text input to numeric
  • Formatting output
  • Error Handling (Exceptions)
  • Message Boxes

27
Chapter 3 Changes
  • Strongly Typed Data
  • Option Strict On
  • Enforces strong data typing
  • Data Types
  • Short (old Integer)
  • Integer (old Long)
  • Decimal (Currency is gone)
  • Object ( Variant is gone)
  • Date (replaces DateTime)

28
Chapter 3 (continued)
  • Initialize a variable at declaration Dim
    intMax As Integer 100I
  • Dim decRate As Decimal 0.08D
  • Declare multiple variables at once Dim
    intCount, intNumber As Integer
  • Convert all input to correct data type (Do not
    use Val function)
  • decSale CDec(txtSale.Text)
  • CDec and CInt Can parse , () -
  • CInt rounds to nearest EVEN number

29
Chapter 3 (continued)
  • New assignment Operators /
  • decTotal decSale
  • Structured Exception Handling
  • Try
  • (Code that could cause an exception)
  • Catch excName As excType
  • (Code to handle the exception)
  • Finally
  • (Code to execute in any case)
  • End Try
  • We can catch input errors before covering If
    statements!

30
Chapter 3 (continued)
  • MessageBox class
  • MessageBox.Show(Arguments)
  • Several choices for argument list
  • Introduces concept of Overloaded functions
  • Multiple signatures to choose from
  • MessageBox.Show(TextMessage)
  • MessageBox.Show(TextMessage, TitlebarText)
  • MessageBox.Show(TextMessage, TitlebarText,
    _ MessageBoxButtons)
  • MessageBox.Show(TextMessage, TitlebarText,
    _ MessageBoxButtons, MessageBoxIcon)

31
Chapter 3 (continued)
  • MessageBox Icons and buttons
  • Enumeration of constants

32
Chapter 4 Decisions and Conditions Topics
Covered
  • Conditions / Relational Operators
  • Block Ifs
  • Compound Conditions
  • Validation
  • Message Boxes that return the user response
  • Debugging

33
Chapter 4 Changes
  • Block IF unchanged
  • Conditions always compare like data types
  • If CInt(txtInput.Text) gt 10I Then
  • String ToUpper and ToLower methods
    (replace UCase and LCase functions)
  • If txtInput.Text.ToUpper YES

34
Chapter 4 (continued)
  • MessageBox.Show method returns an object of
    type DialogResult
  • Dim dgrResponse As DialogResult
  • dgrResponse MessageBox.Show(Shall we?", _
  • "The Question", MessageBoxButtons.YesNo, _
  • MessageBoxIcon.Question)
  • If dgrResponse DialogResult.Yes Then
  • MessageBox.Show("You said Yes!")
  • Else
  • MessageBox.Show("You said No!")
  • End If

35
Chapter 4 (continued)
  • Replace vbCrLf, vbCr, vbLf with constants in the
    ControlChars class
  • ControlChars.NewLine
  • Dim strMultilineMessage As String
  • strMultilineMessage Line 1 _
    ControlChars.NewLine Line 2

36
Chapter 4 (continued)
  • Calling a procedure requires parentheses
  • VB 6 Way
  • ClearControls
  • or Call ClearControls()
  • VB .NET Way
  • Call ClearControls()
  • Calling an event procedure requires two arguments
  • Private Sub btnExit_Click(ByVal sender _ As
    System.Object, ByVal e _ As System.EventArgs)
    Handles btnExit.Click
  • Call the event procedure
  • Call btnExit_Click(sender, e)

37
Chapter 4 (continued)
  • Debug.WriteLine
  • (Replaces Debug.Print)
  • Debug.WriteLine(I got this far)
  • Clear the Output Window
  • Right-click / Clear All
  • New Autos window shows current value of
    variables and objects within approx. 6 statements
  • Immediate window only valid at run time
  • Keyboard shortcut for Step Into F11

38
Chapter 5 Menus, Sub Procedures, and Sub
Functions Topics Covered
  • Creating Menus and Menu Items
  • Creating ContextMenus
  • Displaying Common Dialog Boxes
  • Writing General Procedures

39
Chapter 5 Changes
  • Create a menu by adding a MainMenu control to the
    component tray
  • Great new Menu Designer replaces the Menu Editor

40
Chapter 5 (continued)
  • For Context menus, add a ContextMenu control
  • A ContextMenu uses the same Menu Designer as a
    MainMenu
  • Attach a context menu by setting the ContextMenu
    property of a control or the form

41
Chapter 5 (continued)
  • New ColorDialog and FontDialog controls
  • Added to the component tray
  • Use the controls Show method to display
  • Can set and retrieve properties of the control
  • With dlgColor
  • .Color frmMain.BackColor
  • .ShowDialog()
  • .frmMain.BackColor .Color
  • End With

42
Chapter 5 (continued)
  • The FontDialog control
  • 'Change the font for the total label
  • With dlgFont
  • .Font lblTotal.Font
  • .ShowDialog()
  • lblTotal.Font .Font
  • End With

43
Chapter 5 (continued)
  • Arguments are passed ByVal (by default)
  • The Editor adds ByVal if you leave it out
  • New Return statement
  • Can still set function name to value
  • Better to use the Return statement
  • Private Function CalculateSum( _
  • ByVal intNum1 As Integer, _
  • ByVal intNum2 As Integer) As Integer
  • 'Calculate the sum of the numbers
  • Return intNum1 intNum2
  • End Function

44
Chapter 6 OOP Topics Covered
  • Object-oriented terminology
  • Multitier applications
  • Class vs. Object
  • Visibility Public, Private, Protected
  • Constructors
  • Instantiation
  • Inheritance

45
Chapter 6 Changes
  • Namespaces
  • Organize class libraries
  • Provide unique naming region
  • Can create your own namespace
  • Specifying namespaces
  • lblMessage.Font New System.Drawing.Font( _
  • "Arial", 12)
  • or
  • Imports System.Drawing.Font
  • ...
  • lblMessage.Font New Font("Arial", 12)

46
Chapter 6 (continued)
  • Classes vs. Objects
  • Use New keyword to instantiate
  • For exception handling, declare the name at the
    module level and instantiate in a Try/Catch block
  • Encapsulation
  • Classes hide implementation details
  • Only the Public properties and methods can be
    seen by other classes

47
Chapter 6 (continued)
  • Inheritance
  • New class based on existing class

48
Chapter 6 (continued)
  • Inheritance (continued)
  • All public properties and methods are inherited
  • Visual inheritance can inherit a form
  • New keywords to support inheritance
  • Inherits
  • Overrides
  • Overridable
  • Public Class StudentBookSale
  • Inherits BookSale

49
Chapter 6 (continued)
  • Inheritance (continued)
  • In base class
  • Public Overridable Function _
    ExtendedPrice() As Decimal
  • In derived class
  • Overrides Function ExtendedPrice() _ As
    Decimal

50
Chapter 6 (continued)
  • Polymorphism
  • Consistent naming, so that many classes can have
    the identically-named methods that perform an
    action appropriate for the object
  • Example The Add method for collections, lists,
    arrays, database
  • Identically named methods in a class, with
    different implementations based on the arguments
  • Keyword Overloads
  • Example MessageBox.Show method, which has many
    different argument lists (signatures)

51
Chapter 6 (continued)
  • New Format for Property Procedures
  • Private mstrLastName As String
  • Public Property LastName As String
  • Get
  • LastName mstrLastName
  • End Get
  • Set (ByVal Value As String)
  • mstrLastName Value
  • End Set
  • End Property

52
Chapter 6 (continued)
  • ReadOnly and WriteOnly keywords for properties
  • Private mdecTotalPay As Decimal
  • ReadOnly Property SalesTotal() As Decimal
  • Get
  • TotalPay mdecTotalPay
  • End Get
  • End Property

53
Chapter 6 (continued)
  • Shared members one variable for for all
    instances of the class
  • Often used for totals and counts
  • 'SalesTotal property
  • Private Shared mdecSalesTotal As Decimal
  • 'SalesCount property
  • Private Shared mintSalesCount As Integer

54
Chapter 6 (continued)
  • Constructors New() method
  • Replaces ClassInitialize procedure
  • Constructors are not inherited
  • Must write your own New() procedure
  • First statement should be
  • MyBase.New()
  • Constructors can be overloaded
  • Parameterized Constructors
  • mBookSale New BookSale(txtTitle.Text, _
  • CInt(txtQuantity.Text), _
  • CDec(txtPrice.Text))

55
Chapter 6 (continued)
  • Visibility
  • Private
  • Public
  • Protected
  • Accessible only inside the class or a derived
    class
  • Garbage Collection is automatic
  • Dont set objects to Nothing in code

56
Chapter 7 Lists, Loops, and Printing Topics
Covered
  • List Boxes and Combo Boxes
  • Items Collection
  • Methods and Properties of Lists
  • Do Loops
  • For/Next Loops
  • Printing and Print Preview

57
Chapter 7 Changes
  • The DropDownStyle property of ComboBoxes replaces
    the Style property
  • No List property or ItemData property
  • Lists have an Items collection
  • Items.Add(value)
  • Items.Insert(position)
  • Items.Remove(text string)
  • Items.RemoveAt(index)
  • Items.Clear()
  • Items.Count
  • SelectedIndex property of control

58
Chapter 7 (continued)
  • lstSchools.Items.Add("Harvard")
  • cboMajors.Items.Insert(1, cboMajors.Text)
  • intTotalItems lstItem.Items.Count
  • strSelectedFlavor _ lstFlavor.Items(lstFlavor
    .SelectedIndex)
  • cboCoffee.Items.RemoveAt( _ cboCoffee.SelectedInd
    ex)
  • cboCoffee.Items.Remove(cboCoffee.Text)

59
Chapter 7 (continued)
  • New events
  • SelectedIndexChanged
  • Event to use when the user makes a selection
  • Click event no longer supported for lists
  • TextChanged
  • One event for each keystroke
  • Enter and Leave replace GotFocus and LostFocus
    events
  • FindString and FindStringExact methods
  • Not covered in this text
  • SelectAll method
  • For text boxes or text portion of a combo box

60
Chapter 7 (continued)
  • Printing is completely changed
  • No more Printer.Print, Form.Print,
    PictureBox.Print
  • All text printing is performed with a DrawString
    method on a Graphics object
  • Add a PrintDocument control to the component tray
  • Write all printing logic in the controls
    PrintPage event procedure
  • The control fires the event once for each page to
    print
  • The program responds in the PrintPage event
    procedure

61
Chapter 7 (continued)
  • Begin a printing operation
  • Private Sub btnPrint_Click(ByVal _ sender As
    System.Object, ByVal _
  • e As System.EventArgs) _
  • Handles btnPrint.Click
  • 'Print output on the printer
  • 'Start the print process
  • prtDocument.Print()
  • End Sub

62
Chapter 7 (continued)
  • Set up print page in the controls PrintPage
    event
  • Private Sub prtDocument_PrintPage( _ ByVal sender
    As Object, ByVal e As _ System.Drawing.Printing.Pr
    intPageEventArgs)_ Handles prtDocument.PrintPage
  • 'Set up actual output to print
  • End Sub

63
Chapter 7 (continued)
  • Use the DrawString method in the controls
    PrintPage event
  • 'Declarations at the top of the procedure
  • Dim fntPrintFont As New Font("Arial", 12)
  • 'More declarations here
  • 'Print a line
  • e.Graphics.DrawString(strPrintLine, _
    fntPrintFont, Brushes.Black, _
  • sngPrintX, sngPrintY)

64
Chapter 7 (continued)
  • Graphics objects
  • Must define fonts and brushes to create text
  • Set up print lines with the DrawString method
  • Print Preview
  • Add a PrintPreviewDialog control to the form
  • Assign the PrintDocument control to the
    PrintPreviewDialogs Document property
  • The same PrintPage event procedure is used to set
    up the print output
  • ppdPrintPreview.Document prtDocument
  • ppdPrintPreview.ShowDialog()

65
Chapter 7 (continued)
  • The Good News
  • Do Loops and For / Next Loops are unchanged

66
Chapter 8 Arrays Topics Covered
  • Select Case structure
  • Shared events
  • Arrays
  • Structures
  • Table lookup
  • Combining list controls and arrays
  • Multi-dimensional arrays

67
Chapter 8 Changes
  • Shared events (no control arrays)
  • Private Sub radBlue_CheckedChanged( _ ByVal
    sender As System.Object, _
  • ByVal e As System.EventArgs) _
  • Handles radBlue.CheckedChanged,
    radBlack.CheckedChanged, _
  • radRed.CheckedChanged, _ radWhite.CheckedChang
    ed, _
  • radYellow.CheckedChanged

68
Chapter 8 (continued)
  • In shared event procedure
  • 'Save the name of the selected button
  • Dim radSelected As RadioButton
  • radSelected CType(sender, RadioButton)
  • Select Case radSelected.Name
  • Case "radBlue"
  • mcolorNew Color.Blue
  • Case "radBlack"
  • mcolorNew Color.Black
  • Case "radRed"
  • ' rest of code
  • End Select

69
Chapter 8 (continued)
  • All arrays are zero based
  • No Dim Array(LowerBound To UpperBound)
  • Declare upper subscript unless initializing
    values at declaration
  • Dim mstrProduct(99) As String
  • Dim mintValue() As Integer _ 1, 5, 12, 18,
    20

70
Chapter 8 (continued)
  • Structures replace User-defined Types
  • Public Structure Product
  • Dim strDescription As String
  • Dim strID As String
  • Dim intQuantity As Integer
  • Dim decPrice As Decimal
  • End Structure

71
Chapter 9 Web Forms Topics Covered
  • Client vs. Server
  • Running Web Forms in a browser
  • Web controls
  • Event structure of Web programs
  • Layouts
  • Validator Controls

72
Chapter 9 All New
  • Must install IIS before installing VS .NET
  • Properties, methods, and events are different
    from Windows Forms
  • Examples
  • Name property is ID
  • Form_Load is Page_Load
  • Web Controls differ from Windows controls even
    when they have the same name

73
Chapter 9 (continued)
  • A Web project is created in Inetpub\wwwroot

74
Chapter 9 (continued)
  • Validator Controls run on the client side,
    eliminating traffic to the server

75
Chapter 9 (continued)
  • Web projects are not easy to transfer from one
    computer or folder to another location

76
Chapter 10 Database Topics Covered
  • ADO.NET
  • XML
  • Datasets in Windows and Web projects
  • Record navigation
  • Parameterized queries
  • Updating a dataset

77
Chapter 10 Changes
  • No Data control
  • Disconnected datasets with an adapter
  • Two adapters available
  • SQL Server
  • OleDb (Works well with Access files)
  • Must write navigation code
  • Data is transferred in XML code
  • Generated automatically

78
Chapter 10 (continued)
OleDbConnection object
Actual data. Can contain multiple tables and
relationships.
Data displays on the form in bound controls
Specific file
Handles data transfer and provides data for
dataset. Uses SQL to specify data to retrieve or
update.
79
Chapter 10 (continued)
  • Use the Server Explorer
  • Manage connections
  • View table structure
  • Drag tables and/or fields to the form to set up
    connection and data adapter

80
Chapter 10 (continued)
  • A Configure Data Adapter wizard steps through
    creating the dataset
  • The dataset can be based on an SQL Select
    statement or a stored procedure
  • The wizard presents a Query Builder for building
    SQL Select statements
  • Similar to the Query Designer in Access
  • Creates the Select statement
  • Can also generate the Insert, Delete, and Update
    SQL statements for updating the dataset
  • You can preview the data from the file

81
Chapter 10 (continued)
  • Bind the data to individual controls with the
    DataBindings properties
  • At Form_Load or Page_Load call the Fill method to
    generate the dataset
  • DataAdapterName.Fill(DataSetName)
  • Dataset is disconnected
  • Windows Forms Bound controls are filled
    automatically
  • Web Forms Must execute the BindData method
  • Bound controls are filled when BindData executes
  • Web Forms are static Only current record is
    transferred

82
Chapter 10 (continued)
  • All new Datagrid controls
  • One for Windows forms another for Web forms
  • Navigation requires code
  • No MoveNext, MovePrevious methods
  • Me.BindingContext(DsBooks1, Books).Position
    1
  • Microsoft recommends one dataset per table
  • Save changes back to the original data source by
    executing the datasets Update method
  • The automatically-generated SQL statements
    execute for any changed rows
  • Insert, Delete, Update

83
Chapter 11 Data Files Topics Covered
  • Use streams to store and retrieve data
  • Save and restore values in a list
  • Use serialization to save the values of an object

84
Chapter 11 Changes
  • Data file handling is completely new
  • Streams transfer data
  • StreamReader
  • StreamWriter
  • Imports System.IO
  • Dim datPhone As StreamWriter
  • datPhone New StreamWriter(strFilePath)
  • datPhone.WriteLine(txtName.Text)
  • datPhone.WriteLine(txtPhone.Text)
  • datPhone.Close()

85
Chapter 11 (continued)
  • StreamReader
  • Imports System.IO
  • Dim datPhone As StreamReader
  • datPhone New StreamReader(strFilePath)
  • If datPhone.Peek ltgt -1 Then
  • lblName.Text datPhone.ReadLine()
  • lblPhone.Text datPhone.ReadLine()
  • End If
  • datPhone.Close()

86
Chapter 11 (continued)
  • OpenFileDialog
  • Display common dialog
  • Allow user to browse for file
  • Dim dgrResult As DialogResult
  • dlgOpen.InitialDirectory Application.StartupPath
  • dgrResult dlgOpen.ShowDialog()
  • If dgrResult ltgt DialogResult.Cancel Then 'User
    didn't click the Cancel button
  • datPhone New StreamReader(dlgOpen.FileName) btn
    Next.Enabled True
  • btnNext_Click(sender, e)
  • End If

87
Chapter 11 (continued)
  • Serialization
  • Save an object to a file
  • The objects class must be declared as
    serializable
  • In the program that creates the object
  • Dim datBooks As FileStream _
  • New FileStream("Books", FileMode.Create)
  • Dim BookFormatter As BinaryFormatter _
  • New BinaryFormatter()
  • BookFormatter.Serialize(datBooks, mBookSale)
  • datBooks.Close()

88
Chapter 11 (continued)
  • Deserialization Restore an object from a file
  • Create a FileStream object in the Open mode
  • Declare a Formatter object
  • Use the Formatter's Deserialize method,
    converting the input to the desired object type
  • Transfer the fields from the object to the screen
  • Close the stream
  • FileStream object has Create and Open modes

89
Chapter 12 Graphics Topics Covered
  • Draw shapes, lines, and filled shapes
  • Instantiate Brush and Pen objects
  • Simple animation
  • Timer component
  • Scroll bars
  • Creating pie charts

90
Chapter 12 All New
  • Graphics use GDI for greater device
    independence
  • Based on System.Drawing namespace
  • Graphics object may be on a form or a control
  • Pens draw lines Brushes draw filled shapes
  • Measurement for graphics is pixels
  • The Scale function is gone

91
Chapter 12 (continued)
  • Create graphics in the forms Paint event
    procedure
  • Declare a Graphics object using the
    PaintEventArgs
  • Private Sub frmDraw_Paint(ByVal sender As Object,
    _
  • ByVal e As System.Windows.Forms.PaintEventArgs)
    _ Handles MyBase.Paint
  • 'Create a graphics object
  • Dim gr As Graphics e.Graphics

92
Chapter 12 (continued)
  • Use a Pen to draw a line or outlined shape
  • Use a Brush for a filled shape
  • Dim gr As Graphics e.Graphics
  • Dim penRed As New Pen(Color.Red)
  • Dim brushBlue As New SolidBrush(Color.Blue)
  • 'Draw a red rectangle
  • gr.DrawRectangle(penRed, 10, 10, 30, 30)
  • 'Draw a blue filled circle
  • gr.FillEllipse(brushBlue, 100, 100, 50, 50)

93
Chapter 12 (continued)
  • The SetBounds method replaces Move
  • SetBounds(intX, intY, intWidth, intHeight)
  • picPlane.SetBounds(intX, intY, _ planeWidth,
    planeHeight)

94
Chapter 12 (continued)
  • PictureBox controls hold many more graphic
    formats
  • Can display an animated GIF file
  • Timer component appears in the component tray
  • Enabled False by default must set to True
  • The Tick event fires when the Interval occurs
  • Scroll bar changes
  • ValueChanged replaces Change event
  • Minimum property replaces Min
  • Maximum property replaces Max

95
Chapter 13 Additional Topics Topics Covered
  • Multiple Document Interfaces (MDI)
  • Windows Common Controls
  • Image Lists
  • Toolbars
  • Status bars
  • Calendar
  • Crystal Reports

96
Chapter 13 Changes
  • An MDI program can have
  • Multiple parent forms
  • Multiple child forms
  • Forms that operate independently
  • You no longer have to use a different form type
    as a parent
  • Set parents IsMdiContainer property to True
  • For child form, set MdiParent property in code
  • Dim frmChildOne As New frmChild()
  • frmChildOne.MdiParent Me

97
Chapter 13 (continued)
  • To create a Window menu, set a menus MdiList
    property to True
  • The Arrange methods are replaced with Layout
    methods
  • Me.LayoutMdi(MdiLayout.TileHorizontal)
  • Me.LayoutMdi(MdiLayout.TileVertical)
  • Me.LayoutMdi(MdiLayout.Cascade)

98
Chapter 13 (continued)
  • New controls added to the chapter
  • Image list
  • status bar
  • toolbar
  • Image List
  • You can add and remove images after attaching the
    list to a toolbar
  • New collection editor makes adding and removing
    images easier

99
Chapter 13 (continued)
  • Toolbar
  • Single ButtonClick event for all buttons on
    toolbar
  • EventArgs argument holds index of clicked button
  • Select Case tlbParent.Buttons.IndexOf(e.Button)
  • Case 0
  • mnuDisplayChildOne_Click(sender, e)
  • Case 1
  • mnuDisplayChildTwo_Click(sender, e)
  • End Select

100
Chapter 13 (continued)
  • Crystal Reports are back and are more powerful
  • No code is required to write a report
  • You design a template and add a
    CrystalReportViewer object to the form

101
Questions ???
102
Thank You
  • We appreciate your being here with us.
  • Have fun. Its a great product and should be fun
    to teach!!!
About PowerShow.com