简体   繁体   中英

Printing System information in printout

So whenever I print, it prints out "System.Windows.Forms.Label, Text". I can only assume that this is because I am trying to put a label to a string... but whats the easiest and best way to fix this?

Additionally, on the very last page of the printout it prints "System.Collections.Generic.List`[System.String]... which is fine, I can reuse the paper... but it would be nice if it didn't do that... I have attached all code relevant to my print out, please let me know if you need more...

Any additional suggestions are welcome (: Thanks!

        Private lines As New List(Of String)


Private loopCount As Integer
Private WithEvents docToPrint As New Printing.PrintDocument

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    lines.Clear()
    lines.Add("")
    lines.Add("")
    lines.Add("Date:" & DateTimePicker1.Value)
    lines.Add("")
    lines.Add("Company Information: ")
    lines.Add("")
    lines.Add("Company Name: " & txtCustName.ToString)
    lines.Add("Part Name: " & txtPartName.ToString)
    lines.Add("Qty per Year: " & yearQty.ToString)
    lines.Add("Qty per Batch/Shipment: " & batchQty.ToString)
    lines.Add("Equipment Used Information: ")
    lines.Add("Vib Machine Used: " & lblVMachineName.ToString)
    lines.Add("Vibratory Media Used: " & lblVibMedia.ToString)
    lines.Add("Liquid Compound Name: " & lblCompname.ToString)
    lines.Add("Labor Cost Per Run: " & laborCostpRun.ToString("C2") & "     Per Peice: " & laborCostpPc.ToString("C2") & "     Per Year: " & laborcostpYr.ToString("C2"))
    lines.Add("Media Cost Per Run: " & mediaCostpRun.ToString("C2") & "     Per Peice: " & mediaCostpPc.ToString("C2") & "     Per Year: " & mediaCostpYr.ToString("C2"))
    lines.Add("Machine Cost per Run: " & machineCostpRun.ToString("C2") & "  Per Peice:: " & machineCostpPc.ToString("C2") & "    Per Year: " & machineCostpYr.ToString("C2"))
    lines.Add("Compound Cost per Run: " & compoundPricepRun.ToString("C2") & "Per Peice: " & compCostpPc.ToString("C2") & "     Per Year: " & compCostpYr.ToString("C2"))
    lines.Add("Factory Overhead per Run: " & factOH.ToString("C2") & "Per Peice: " & facOHpPc.ToString("C2") & "   Per Year: " & facOHpYr.ToString("C2"))
    lines.Add("Total Process Cost per Run: " & processCost.ToString("C2") & "Per Peice: " & processCostpPc.ToString("C2") & "   Per Year: " & processCostpYr.ToString("C2"))
    lines.Add("Business Overhead per Run: " & bOH.ToString("C2") & "Per Peice: " & bOHpPC.ToString("C2") & "   Per Year: " & boOHpYr.ToString("C2"))
    lines.Add("Sales Commision per Run: " & salesComm.ToString("C2") & "Per Peice: " & salesCommpPc.ToString("C2") & "   Per Year: " & salesCommpYr.ToString("C2"))
    lines.Add("Profit per Run: " & profit.ToString("C2") & "Per Peice: " & profitpPc.ToString("C2") & "   Per Year: " & profitpYr.ToString("C2"))
    lines.Add("Total Price per Run: " & grandTotalpRun.ToString("C2") & "Per Peice: " & grandTotalpPc.ToString("C2") & "   Per Year: " & grandTotalpYr.ToString("C2"))
    lines.Add("Runs per Week: " & runspWeek.ToString)
    lines.Add("Runs per Year: " & runspYear.ToString)
    lines.Add("")
    lines.Add("Parameters:")
    lines.Add("")
    lines.Add("As for media, the following costs are implemented:")
    lines.Add("HD-1 Cone: Price: $1.47/lb ; Density/lb: 100 ; Wear Rate: .5")
    lines.Add("F 3/16 Cyl.: Price: $1.54/lb ; Density/lb: 95 ; Wear Rate: 0")
    lines.Add("ECH 7/8 T2: Price: $1.14/lb ; Density/lb: 95 ; Wear Rate: .3")
    lines.Add("ECH 7/16 Cyl: Price: $1.10/lb ; Density/lb: 95 ; Wear Rate: .3")
    lines.Add("3/16 Steel Ball Cone: Price: $3.50/lb ; Density/lb: 270 ; Wear Rate: 0")
    lines.Add("UFX 3/8X3/8 ACT: Price: $.86/lb ; Density/lb: 100 ; Wear Rate: 1")
    lines.Add("XC 7/8 Cyl.: Price: $1.10/lb ; Density/lb: 95 ; Wear Rate: .35")
    lines.Add("LD-2 3/4 Cone: Price: $1.40/lb ; Density/lb: 70 ; Wear Rate: .2")
    lines.Add("HD-1 Tri-Star 1-3/8 X 1/2: Price: $1.47/lb ; Density/lb: 100 ; Wear Rate: .5")
    lines.Add("5/16 Steel Ball Cone: Price: $2.75/lb ; Density/lb: 270 ; Wear Rate: 0")
    lines.Add("25/32 Steel Cone: Price: $3.25/lb ; Density/lb: 270 ; Wear Rate: 0")
    lines.Add("")
    lines.Add("As for machines, the following costs are implemented: ")
    lines.Add("Torex TG-299F: $2/hr")
    lines.Add("Sweco 1.2: $2/hr")
    lines.Add("Torex 6026A: $9/hr")
    lines.Add("Torex 6026B: $9/hr")
    lines.Add("Sweco FM10: $5/hr")
    lines.Add("Sweco FM7: $5/hr")
    lines.Add("VT-5524 F: $11/hr")
    lines.Add("VT-5524 F: $11/hr")
    lines.Add("VTHT-2450: $9/hr")
    lines.Add("")
    lines.Add("As for compounds, the following costs are implemented:")
    lines.Add("Rodeco 211: $3.96/gal")
    lines.Add("Rodeco 551: $4.02/gal")
    lines.Add("Rodeco 553: $6.90/gal")
    lines.Add("Rodeco 4677: $5.48/gal")
    lines.Add("Rodeco 842: $3.74/gal")
    lines.Add("Rodeco 320: $3.42/gal")
    lines.Add("Rodeco 103: $ .89/lb")
    lines.Add("Rodeco 307: $ .79/lb")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("Business Overhead Includes:")
    lines.Add("Office phone, officer salary, bank, dues + subscribitions, employee gifts, rent, accounting, outside maint.,")
    lines.Add(" utilities, office wages. For 2014 this was $463,000.")
    lines.Add("Since 2014 Job Shop Sales was 4% of total sales. 463,000 * 4% = $18,500. ")
    lines.Add("Divided by 4000 direct labor hours, equals 4.65/hr direct labor costs.")
    lines.Add("")
    lines.Add("Factory Overhead Includes: ")
    lines.Add("Item:        Total 2014 Rodeco:      Vib Job Shop        Equip Cost")
    lines.Add("Repair:              $ 27                    $  7                  $ 20")
    lines.Add("Shop Supplies        $ 22                    $ 22                      ")
    lines.Add("Supervisor Labor     $ 50                    $ 20                      ")
    lines.Add("Shop Office          $  2                    $  2                      ")
    lines.Add("Rent                 $167                    $ 24                      ")
    lines.Add("Elect                $ 32                    $  5                  $ 20")
    lines.Add("Business Ins.                                $ 27                  $  3")
    lines.Add("Computer                                     $ 22                  $  3")
    lines.Add("Outside                                      $  2                      ")
    lines.Add("Wastewater                                   $  2                  $  2")
    lines.Add("Deprecition          $ 81                    $ 5                   $ 12")
    lines.Add("                                 $95,000/4000(labor hrs)=       52000/54.45(indirect hrs)    ")
    lines.Add("                                       $23.75/hr            $9.50/hr")
    lines.Add("Sales Commision: 6% of Profit. Profit is 35%")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    lines.Add("")
    docToPrint.Print()

    Dim printer As New myPrinter

End Sub
Private Sub document_PrintPage(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
    PrintDialog1.AllowSomePages = True
    PrintDialog1.ShowHelp = True

    PrintDialog1.Document = docToPrint

    Dim result As DialogResult = PrintDialog1.ShowDialog()

    If (result = DialogResult.OK) Then
        docToPrint.Print()
    End If

End Sub

Private Sub document_PrintPage(ByVal sender As Object, _
   ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
       Handles docToPrint.PrintPage

    Dim printFont As New System.Drawing.Font _
        ("Arial", 12, System.Drawing.FontStyle.Regular)



    Dim row As Integer = 5
    For i = loopCount To lines.Count - 1
        If Not row >= e.MarginBounds.Bottom - 20 Then
            loopCount = i
            e.Graphics.DrawString(lines(i), printFont, System.Drawing.Brushes.Black, 10, row)
            row += 20
        Else
            e.HasMorePages = True
            Exit Sub
        End If
    Next


    ' Draw the content.
    e.Graphics.DrawString(lines.ToString(), printFont, System.Drawing.Brushes.Black, 10, 10)
End Sub

Almost every control has a Text property to reffer to its text content.

Then, you should use that property:

lines.Add("Vib Machine Used: " & lblVMachineName.Text)
lines.Add("Vibratory Media Used: " & lblVibMedia.Text)
lines.Add("Liquid Compound Name: " & lblCompname.Text)

The same for TextBoxes in case of txtCustName and the other are textboxes.

Note that no .ToString extension is need because the Control.Text property is a String datatype, it does not need a conversion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM