Datagridview 값 인쇄 [중복]

Sep 09 2020

Datagridview에서 이것을 인쇄하면 값이 서로 위에 있습니다. 여기에 이미지 설명을 입력하십시오.

Dim rowCount As Integer = DataGridView6.Rows.Count
For i = 0 To rowCount - 1

    e.Graphics.DrawString("PARTICULARS", ReportBodyFont, Brushes.Black, 70, 300)
    e.Graphics.DrawString("QTY", ReportBodyFont, Brushes.Black, 400, 300)
    e.Graphics.DrawString("AMOUNT", ReportBodyFont, Brushes.Black, 600, 300)

    e.Graphics.DrawString("----------------------------------------------------------", ReportFont, Brushes.Black, 50, 310)
    ''
    e.Graphics.DrawString(DataGridView6.Rows(i).Cells(1).Value, ReportBodyFont, Brushes.Black, 50, 320)
    e.Graphics.DrawString(DataGridView6.Rows(i).Cells(3).Value, ReportBodyFont, Brushes.Blue, 400, 320)
    e.Graphics.DrawString(DataGridView6.Rows(i).Cells(2).Value, ReportBodyFont, Brushes.Black, 600, 320)

Next

답변

jmcilhinney Sep 09 2020 at 21:19

물론 그렇습니다. 모든 행에 똑같은 좌표를 사용하고 있습니다. 각 행이 이전 행 아래에 인쇄 될 것으로 예상하는 경우 이전 행보다 큰 Y를 지정해야합니다. 일반적으로 첫 번째 레코드에 대한 기준선과 레코드의 높이를 설정 한 다음 해당 기준선에 높이를 곱한 행 인덱스를 더한 각 행에 대해 Y 좌표를 사용합니다.

Dim y0 = 10
Dim rowHeight = 50

For rowIndex = 0 To rowCount - 1
    Dim y = y0 + rowIndex * rowHeight

    'Print at y.
Next