我正在使用Printdocument创建收据 数据来自datagridview。条件是,一旦datagridview col1上char的长度> 10,就在col1的下一行打印col2。并再次在col1上继续下一行新数据。错误是col1上的下一个数据与row1 col2数据重叠。
Dim I As Integer
For I = 0 To dvProducts.Rows.Count - 1
Dim yloc = (20 * I) + 90
Dim L As Integer
L = dvProducts.Rows(I).Cells(0).Value.ToString.Length
If L > 10 Then
e.Graphics.DrawString(dvProducts.Rows(I).Cells(0).Value, font2, Brushes.Black, 10, yloc)
yloc = (20 * I) + 90 + 20
e.Graphics.DrawString(dvProducts.Rows(I).Cells(1).Value, font2, Brushes.Black, 110, yloc)
e.Graphics.DrawString(Val(dvProducts.Rows(I).Cells(2).Value).ToString("N"), font2, Brushes.Black, 150, yloc)
e.Graphics.DrawString(dvProducts.Rows(I).Cells(3).Value, font2, Brushes.Black, 230, yloc, left)
'Dim dvcount As Integer = dvProducts.Rows.Count
'Dim newloc As Integer = dvcount * 20 + 100
'e.Graphics.DrawString("Total Amount:", font2, Brushes.Black, 100, newloc + 10)
'e.Graphics.DrawString(txtgt.Text, font2, Brushes.Black, 230, newloc + 10, left)
'e.Graphics.DrawString("Cash:", font2, Brushes.Black, 100, newloc + 30)
'e.Graphics.DrawString(Val(txtTender.Text).ToString("N"), font2, Brushes.Black, 230, newloc + 30, left)
'e.Graphics.DrawString("Change", font2, Brushes.Black, 100, newloc + 50)
'e.Graphics.DrawString(txtChange.Text, font2, Brushes.Black, 230, newloc + 50, left)
'e.Graphics.DrawString("Date: " & dtptdate.Text & "", font2, Brushes.Black, 10, newloc + 90)
Else
e.Graphics.DrawString(dvProducts.Rows(I).Cells(0).Value, font2, Brushes.Black, 10, yloc)
e.Graphics.DrawString(dvProducts.Rows(I).Cells(1).Value, font2, Brushes.Black, 110, yloc)
e.Graphics.DrawString(Val(dvProducts.Rows(I).Cells(2).Value).ToString("N"), font2, Brushes.Black, 150, yloc)
e.Graphics.DrawString(dvProducts.Rows(I).Cells(3).Value, font2, Brushes.Black, 230, yloc, left)
End If
Next