IMPRIMIR DATAVIEWGRID
Publicado por Jaime (19 intervenciones) el 30/07/2019 16:16:22
Alguien conoce la manera de imprimir un Dataviewgrid ? me gustaria conservar el formato original que está asignado cuando se hace el llenado ya que tengo algunos valores en formato bold, intenté con el siguiente código pero al momento de dar click me aparece que no visualiza ningún documento, además me gustaría agregar un textbox que sea el titulo de lo que quiero imprimir, como podría lograrlo?
Gracias de antemano y saludos.
Gracias de antemano y saludos.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Private Sub btnPrint_Click_1(sender As Object, e As EventArgs) Handles btnPrint.Click
PrintDocument1.DefaultPageSettings.Landscape = True
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim CenterAlign As New StringFormat
CenterAlign.Alignment = StringAlignment.Center
Dim RightAlign As New StringFormat
CenterAlign.Alignment = StringAlignment.Far
e.Graphics.DrawString("Operación", New Font("Arial", 16, FontStyle.Bold), Brushes.Black, New Point(25, 25))
e.Graphics.DrawString("Fecha Inicial", New Font("Arial", 16, FontStyle.Bold), Brushes.Black, New Point(1000, 25), RightAlign)
e.Graphics.DrawString("Fecha Final", New Font("Arial", 16, FontStyle.Bold), Brushes.Black, New Point(1000, 25), RightAlign)
e.Graphics.DrawString("Estatus", New Font("Arial", 16, FontStyle.Bold), Brushes.Black, New Point(1000, 25), RightAlign)
Dim mRow As Integer = 0
Dim newpage As Boolean = True
With DataGridView1
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
fmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
Dim y As Single = e.MarginBounds.Top
Do While mRow < .RowCount
Dim row As DataGridViewRow = .Rows(mRow)
Dim x As Single = e.MarginBounds.Left
Dim h As Single = 0
For Each cell As DataGridViewCell In row.Cells
Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
If (newpage) Then
e.Graphics.DrawString(DataGridView1.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
Else
e.Graphics.DrawString(DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
End If
x += rc.Width
h = Math.Max(h, rc.Height)
Next
newpage = False
y += h
mRow += 1
If y + h > e.MarginBounds.Bottom Then
e.HasMorePages = True
mRow -= 1
newpage = True
Exit Sub
End If
Loop
mRow = 0
End With
End Sub
Valora esta pregunta


0