'Project:       Ch7 HandsOn

'Programmer:    Brad Shedd

'Date:          July 27, 2006

'Description:   maintain a list of coffee flavors; print the selected flavor of coffee and syrup or print a list of the coffee flavors.

 

Public Class frmMain

 

 

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

        Me.Close()

    End Sub

 

    Private Sub AddCoffeeFlavorToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddCoffeeFlavorToolStripMenuItem.Click

        With Me.cbxCoffee

            If .Text <> "" Then

                'make sure item is not on list

                Dim itemFoundBoolean As Boolean

                Dim itemIndexInteger As Integer

                Do Until itemFoundBoolean Or itemIndexInteger = .Items.Count

                    If .Text = .Items(itemIndexInteger).ToString() Then

                        itemFoundBoolean = True

                        Exit Do

                    Else

                        itemIndexInteger += 1

                    End If

                Loop

                If itemFoundBoolean Then

                    MessageBox.Show("Duplicate Item.", "Add Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                Else

                    'add it

                    .Items.Add(.Text)

                    .Text = ""

                End If

            Else

                MessageBox.Show("Enter a coffee flavor to add", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            End If

            .Focus()

        End With

    End Sub

 

    Private Sub PrintAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintAllToolStripMenuItem.Click

        'begin the print process to print all items.

        printAllPrintDocument.Print()

    End Sub

 

    Private Sub PreviewAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PreviewAllToolStripMenuItem.Click

        'begin the process for print preview of all items

 

        PrintPreviewDialog1.Doument = printAllDocument

        PrintPreviewDialog1.ShowDialog()

    End Sub

 

    Private Sub PrintSelectedToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintSelectedToolStripMenuItem.Click

        'begin the print process to print the selected item.

 

        With Me

            If .lbxSyrup.SelectedIndex = -1 Then

                'select none if nothing selected

                .lbxSyrup.SelectedIndex = 0

            End If

            If .cbxCoffee.SelectedIndex <> -1 Then

                'items selected

                .printSelectedPrintDocument.Print()

            Else

                'no item selected

                MessageBox.Show("Select a flavor from the coffee list", "Print Selection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            End If

        End With

    End Sub

    Private Sub PreviewSelectedToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PreviewSelectedToolStripMenuItem.Click

        'begin the process for print preview of the selected item.

 

        With Me

            If .lbxSyrup.SelectedIndex = -1 Then

                'select none if nothing is selected

                .lbxSyrup.SelectedIndex = 0

            End If

            If .cbxCoffee.SelectedIndex <> -1 Then

                'item selected

                .PrintPreviewDialog1.Document = printSelectedPrintDocument

                .PrintPreviewDialog1.ShowDialog()

            Else

                'no item seleceted

                MessageBox.Show("Select a flavor from the coffee list", "Print Selection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            End If

        End With

 

    End Sub

    Private Sub printAllPrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.PrintPageEventArgs)_ Handles printAllPrintDocument.PrintPage

 

        'Handles printAllPrintDocument.PrintPage

 

        Dim printFont As New Font("Arial", 12)

        Dim lineHeightSingle As Single = printFont.GetHeight + 2

        Dim horizontalPrintLocationsSingle

    End Sub

End Class

 

 

Homepage