所以每当我打印时,它都会打印出"System.Windows.Forms.Label,Text"。我只能假设这是因为我试图给字符串加一个标签。。。但解决这个问题最简单、最好的方法是什么?
此外,在打印输出的最后一页,它打印出"System.Collections.Generic.List`[System.String]……这很好,我可以重复使用纸张……但如果它不这样做,那就太好了……我已经附上了与打印输出相关的所有代码,如果你需要更多,请告诉我…
欢迎任何其他建议(:谢谢!
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
几乎每个控件都有一个Text
属性来引用其文本内容。
然后,您应该使用该属性:
lines.Add("Vib Machine Used: " & lblVMachineName.Text)
lines.Add("Vibratory Media Used: " & lblVibMedia.Text)
lines.Add("Liquid Compound Name: " & lblCompname.Text)
在txtCustName
的情况下,TextBoxes也是如此,其他都是文本框。
请注意,不需要.ToString
扩展,因为Control.Text
属性是String数据类型,因此不需要转换。