Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching an Introductory Programming Class Using Visual Basic.NET.

Similar presentations

Presentation on theme: "Teaching an Introductory Programming Class Using Visual Basic.NET."— Presentation transcript:

1 Teaching an Introductory Programming Class Using Visual Basic.NET

2 Spring 2002 Slide 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 Spring 2002 Slide 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 Spring 2002 Slide 4 Our Goals for Today n Help you transition from VB 6 to VB.NET n Look at the differences between Visual Basic 6:object based; event driven Visual Basic.NET: object oriented n Introduce the new Visual Studio IDE (integrated development environment) n Show the changes to the language and the new features

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

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

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

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

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

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

11 Spring 2002 Slide 11 Chapter 1 Changes n New IDE

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

13 Spring 2002 Slide 13 Chapter 1 ( continued ) Push Pin Locked Control Tabbed Window

14 Spring 2002 Slide 14 Chapter 1 ( continued ) nA solution can contain multiple projects nForms, classes, and code modules have a.vb extension nThe IDE automatically creates a folder for the project

15 Spring 2002 Slide 15 n Form Designer l Similar to VB 6 l 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 l Locked controls have a dark border when selected n Command Buttons are now Buttons l Use btn for prefix l No more Caption property now it is Text Chapter 1 (continued )

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

17 Spring 2002 Slide 17 Chapter 1 ( continued ) Collapsed Region Collapsed Procedure Class List Method List Tabs

18 Spring 2002 Slide 18 Chapter 1 ( continued ) n Complications: l Changing the name of the form requires the projects startup object to be changed l PrintForm is no longer supported l IDE Print does not offer Form Image or Form Text l No edit-and-continue execution – Must restart (recompile) if edits are made during break time

19 Spring 2002 Slide 19 Chapter 1 ( continued ) nForm and controls no longer have Caption property nForms, buttons, labels all use the Text property nThe Alignment property becomes TextAlign nThe maximum length of identifiers is 16,383 nAll new Help MSDN nRedesigned Object Browser nMe.Close()

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

21 Spring 2002 Slide 21 Chapter 2 Changes nNo more Image control, Line control, or Shape control nUse PictureBox for graphics; Label for lines nOptionButton becomes RadioButton nFrame becomes GroupBox nAcceptButton and CancelButton are properties of the form nSet the forms StartPosition property; no more Form Layout Window

22 Spring 2002 Slide 22 Chapter 2 ( continued ) nPictureBox controls l Use Image property to hold a graphic l Set SizeMode property to StretchImage replaces Stretch property of Images nCheckBox controls l Value property becomes the Checked property (Boolean) l Its event is CheckChanged nGreat new method for setting tab order

23 Spring 2002 Slide 23 Chapter 2 ( continued ) View / Tab Order

24 Spring 2002 Slide 24 nNew component tray holds non-visible controls nTo add ToolTips, add a ToolTip control to the component tray lNew ToolTip on ToolTip1 property is added to the form and all controls nText boxes have a Clear method txtName.Clear() txtName.Text = n Focus method replaces SetFocus txtName.Focus() Chapter 2 ( continued )

25 Spring 2002 Slide 25 nMany 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 Chapter 2 ( continued )

26 Spring 2002 Slide 26 Chapter 3 Variables, Constants and Calculations Topics Covered nVariables, constants, calculations nData types nConverting text input to numeric nFormatting output nError Handling (Exceptions) nMessage Boxes

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

28 Spring 2002 Slide 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 n Convert all input to correct data type (Do not use Val function) decSale = CDec(txtSale.Text) n CDec and CInt Can parse: $, () + - n CInt rounds to nearest EVEN number

29 Spring 2002 Slide 29 Chapter 3 ( continued ) nNew assignment Operators += – = * = /= &= decTotal += decSale nStructured 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 nWe can catch input errors before covering If statements!

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

31 Spring 2002 Slide 31 Chapter 3 ( continued ) n MessageBox Icons and buttons l Enumeration of constants

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

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

34 Spring 2002 Slide 34 Chapter 4 ( continued ) n 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 Spring 2002 Slide 35 Chapter 4 ( continued ) nReplace vbCrLf, vbCr, vbLf with constants in the ControlChars class ControlChars.NewLine Dim strMultilineMessage As String strMultilineMessage = Line 1 & _ ControlChars.NewLine & Line 2

36 Spring 2002 Slide 36 Chapter 4 ( continued ) nCalling a procedure requires parentheses VB 6 Way: ClearControls or Call ClearControls() VB.NET Way: [Call] ClearControls() nCalling an event procedure requires two arguments Private Sub btnExit_Click(ByVal sender _ As System.Object, ByVal e _ As System.EventArgs) Handles btnExit.Click nCall the event procedure: [Call] btnExit_Click(sender, e)

37 Spring 2002 Slide 37 Chapter 4 ( continued ) nDebug.WriteLine (Replaces Debug.Print) Debug.WriteLine(I got this far) nClear the Output Window: Right-click / Clear All nNew Autos window shows current value of variables and objects within approx. 6 statements nImmediate window only valid at run time nKeyboard shortcut for Step Into F11

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

39 Spring 2002 Slide 39 Chapter 5 Changes nCreate a menu by adding a MainMenu control to the component tray nGreat new Menu Designer replaces the Menu Editor

40 Spring 2002 Slide 40 Chapter 5 ( continued ) nFor Context menus, add a ContextMenu control nA ContextMenu uses the same Menu Designer as a MainMenu nAttach a context menu by setting the ContextMenu property of a control or the form

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

42 Spring 2002 Slide 42 Chapter 5 ( continued ) nThe FontDialog control 'Change the font for the total label With dlgFont.Font = lblTotal.Font.ShowDialog() lblTotal.Font =.Font End With

43 Spring 2002 Slide 43 Chapter 5 ( continued ) nArguments are passed ByVal (by default) The Editor adds ByVal if you leave it out n 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 Spring 2002 Slide 44 Chapter 6 OOP Topics Covered n Object-oriented terminology n Multitier applications n Class vs. Object n Visibility Public, Private, Protected n Constructors n Instantiation n Inheritance

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

46 Spring 2002 Slide 46 Chapter 6 ( continued ) n 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 n Encapsulation Classes hide implementation details Only the Public properties and methods can be seen by other classes

47 Spring 2002 Slide 47 Chapter 6 ( continued ) nInheritance New class based on existing class

48 Spring 2002 Slide 48 Chapter 6 ( continued ) nInheritance (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 Spring 2002 Slide 49 Chapter 6 ( continued ) nInheritance (continued) In base class Public Overridable Function _ ExtendedPrice() As Decimal In derived class Overrides Function ExtendedPrice() _ As Decimal

50 Spring 2002 Slide 50 Chapter 6 ( continued ) nPolymorphism 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 Spring 2002 Slide 51 Chapter 6 ( continued ) n 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 Spring 2002 Slide 52 Chapter 6 ( continued ) n ReadOnly and WriteOnly keywords for properties Private mdecTotalPay As Decimal ReadOnly Property SalesTotal() As Decimal Get TotalPay = mdecTotalPay End Get End Property

53 Spring 2002 Slide 53 Chapter 6 ( continued ) nShared 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 Spring 2002 Slide 54 Chapter 6 ( continued ) nConstructors 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 nParameterized Constructors mBookSale = New BookSale(txtTitle.Text, _ CInt(txtQuantity.Text), _ CDec(txtPrice.Text))

55 Spring 2002 Slide 55 Chapter 6 ( continued ) n Visibility Private Public Protected –Accessible only inside the class or a derived class nGarbage Collection is automatic Dont set objects to Nothing in code

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

57 Spring 2002 Slide 57 Chapter 7 Changes nThe DropDownStyle property of ComboBoxes replaces the Style property nNo List property or ItemData property nLists have an Items collection Items.Add(value) Items.Insert(position) Items.Remove(text string) Items.RemoveAt(index) Items.Clear() Items.Count nSelectedIndex property of control

58 Spring 2002 Slide 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.SelectedIndex) cboCoffee.Items.Remove(cboCoffee.Text)

59 Spring 2002 Slide 59 Chapter 7 ( continued ) nNew 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 n FindString and FindStringExact methods Not covered in this text n SelectAll method For text boxes or text portion of a combo box

60 Spring 2002 Slide 60 Chapter 7 ( continued ) nPrinting is completely changed No more Printer.Print, Form.Print, PictureBox.Print nAll text printing is performed with a DrawString method on a Graphics object nAdd 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 Spring 2002 Slide 61 Chapter 7 ( continued ) nBegin 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 Spring 2002 Slide 62 Chapter 7 ( continued ) nSet up print page in the controls PrintPage event: Private Sub prtDocument_PrintPage( _ ByVal sender As Object, ByVal e As _ System.Drawing.Printing.PrintPageEventArgs)_ Handles prtDocument.PrintPage 'Set up actual output to print End Sub

63 Spring 2002 Slide 63 Chapter 7 ( continued ) nUse 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 Spring 2002 Slide 64 Chapter 7 ( continued ) nGraphics objects Must define fonts and brushes to create text nSet up print lines with the DrawString method nPrint 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 Spring 2002 Slide 65 Chapter 7 ( continued ) nThe Good News: Do Loops and For / Next Loops are unchanged

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

67 Spring 2002 Slide 67 Chapter 8 Changes n 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.CheckedChanged, _ radYellow.CheckedChanged

68 Spring 2002 Slide 68 Chapter 8 ( continued ) n 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 Spring 2002 Slide 69 Chapter 8 ( continued ) nAll arrays are zero based No Dim Array(LowerBound To UpperBound) n Declare upper subscript unless initializing values at declaration Dim mstrProduct(99) As String Dim mintValue() As Integer _ = {1, 5, 12, 18, 20}

70 Spring 2002 Slide 70 Chapter 8 ( continued ) nStructures 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 Spring 2002 Slide 71 Chapter 9 Web Forms Topics Covered n Client vs. Server n Running Web Forms in a browser n Web controls n Event structure of Web programs n Layouts n Validator Controls

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

73 Spring 2002 Slide 73 Chapter 9 ( continued ) nA Web project is created in Inetpub\wwwroot

74 Spring 2002 Slide 74 Chapter 9 ( continued ) nValidator Controls run on the client side, eliminating traffic to the server

75 Spring 2002 Slide 75 Chapter 9 ( continued ) nWeb projects are not easy to transfer from one computer or folder to another location

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

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

78 Spring 2002 Slide 78 Chapter 10 ( continued ) Specific file OleDbConnection object Handles data transfer and provides data for dataset. Uses SQL to specify data to retrieve or update. Actual data. Can contain multiple tables and relationships. Data displays on the form in bound controls

79 Spring 2002 Slide 79 Chapter 10 ( continued ) nUse the Server Explorer Manage connections View table structure Drag tables and/or fields to the form to set up connection and data adapter

80 Spring 2002 Slide 80 Chapter 10 ( continued ) nA Configure Data Adapter wizard steps through creating the dataset nThe dataset can be based on an SQL Select statement or a stored procedure nThe 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 n You can preview the data from the file

81 Spring 2002 Slide 81 Chapter 10 ( continued ) nBind the data to individual controls with the DataBindings properties nAt Form_Load or Page_Load call the Fill method to generate the dataset DataAdapterName.Fill(DataSetName) nDataset is disconnected nWindows Forms Bound controls are filled automatically nWeb Forms Must execute the BindData method Bound controls are filled when BindData executes nWeb Forms are static Only current record is transferred

82 Spring 2002 Slide 82 Chapter 10 ( continued ) nAll new Datagrid controls One for Windows forms; another for Web forms nNavigation requires code No MoveNext, MovePrevious methods Me.BindingContext(DsBooks1, Books).Position += 1 nMicrosoft recommends one dataset per table nSave 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 Spring 2002 Slide 83 Chapter 11 Data Files Topics Covered nUse streams to store and retrieve data nSave and restore values in a list nUse serialization to save the values of an object

84 Spring 2002 Slide 84 Chapter 11 Changes n Data file handling is completely new n 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 Spring 2002 Slide 85 Chapter 11 ( continued ) nStreamReader Imports System.IO Dim datPhone As StreamReader datPhone = New StreamReader(strFilePath) If datPhone.Peek <> -1 Then lblName.Text = datPhone.ReadLine() lblPhone.Text = datPhone.ReadLine() End If datPhone.Close()

86 Spring 2002 Slide 86 Chapter 11 ( continued ) nOpenFileDialog Display common dialog Allow user to browse for file Dim dgrResult As DialogResult dlgOpen.InitialDirectory = Application.StartupPath dgrResult = dlgOpen.ShowDialog() If dgrResult <> DialogResult.Cancel Then 'User didn't click the Cancel button datPhone = New StreamReader(dlgOpen.FileName) btnNext.Enabled = True btnNext_Click(sender, e) End If

87 Spring 2002 Slide 87 Chapter 11 ( continued ) nSerialization 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 Spring 2002 Slide 88 Chapter 11 ( continued ) nDeserialization 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 nFileStream object has Create and Open modes

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

90 Spring 2002 Slide 90 Chapter 12 All New nGraphics use GDI+ for greater device independence nBased on System.Drawing namespace nGraphics object may be on a form or a control nPens draw lines; Brushes draw filled shapes nMeasurement for graphics is pixels The Scale function is gone

91 Spring 2002 Slide 91 Chapter 12 ( continued ) nCreate graphics in the forms Paint event procedure nDeclare 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 Spring 2002 Slide 92 Chapter 12 ( continued ) nUse a Pen to draw a line or outlined shape nUse 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 Spring 2002 Slide 93 Chapter 12 ( continued ) nThe SetBounds method replaces Move SetBounds(intX, intY, intWidth, intHeight) picPlane.SetBounds(intX, intY, _ planeWidth, planeHeight)

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

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

96 Spring 2002 Slide 96 Chapter 13 Changes nAn MDI program can have Multiple parent forms Multiple child forms Forms that operate independently nYou 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 Spring 2002 Slide 97 Chapter 13 ( continued ) nTo create a Window menu, set a menus MdiList property to True nThe Arrange methods are replaced with Layout methods Me.LayoutMdi(MdiLayout.TileHorizontal) Me.LayoutMdi(MdiLayout.TileVertical) Me.LayoutMdi(MdiLayout.Cascade)

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

99 Spring 2002 Slide 99 Chapter 13 ( continued ) nToolbar 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 Spring 2002 Slide 100 Chapter 13 ( continued ) nCrystal Reports are back and are more powerful nNo code is required to write a report nYou design a template and add a CrystalReportViewer object to the form

101 Spring 2002 Slide 101 Questions ???

102 Spring 2002 Slide 102 Thank You We appreciate your being here with us. Have fun. Its a great product and should be fun to teach!!!

Download ppt "Teaching an Introductory Programming Class Using Visual Basic.NET."

Similar presentations

Ads by Google