
Como puedo imprimir fecha sin hora
Publicado por anonymous (114 intervenciones) el 15/09/2020 12:58:02
Hola tengo un form con un botón de imprimir una BD Access. En el datagrid me muestra el campo fecha bien, osea, sólo la fecha pero cuando imprimo la BD me lo imprime como fecha/hora aunque el campo está declarado como fecha y fecha corta. ¿Qué puedo hacer? Gracias.
Adjunto el código del botón:
Adjunto el código del botón:
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'DEFINIMOS LA FUENTE QUE VAMOS A USAR PARA IMPRIMIRDim printFont As System.Drawing.Font = New Drawing.Font("Verdana", 10, FontStyle.Regular)
Dim topmargin As Double = e.MarginBounds.Top
Dim yPos As Double = 0 Dim linesPerPage As Double = 0 Dim count As Integer = 0Dim texto As String = ""
Dim row As System.Windows.Forms.DataGridViewRow
'CALCULAMOS EL NÚMERO DE LÍNEAS QUE CABEN EN CADA PÁGINAlinesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
'IMPRIMIMOS LAS CABECERASDim header As DataGridViewHeaderCell
For Each column As DataGridViewColumn In DataGridView1.Columnsheader = column.HeaderCell
texto += " " & header.FormattedValue.ToString() & " "
Next
yPos = topmargin + (count * printFont.GetHeight(e.Graphics))
e.Graphics.DrawString(texto, printFont, System.Drawing.Brushes.Black, 10, yPos)
'DEJAMOS UNA LÍNEA DE SEPARACIÓNcount += 2
'RECORREMOS EL DATAGRIDVIEW HASTA LLEGAR AL TOPE DE LÍNEAS DE LA PÁGINA O EL FINAL DEL DATAGRIDVIEWWhile count < linesPerPage AndAlso i < DataGridView1.Rows.Count
row = DataGridView1.Rows(i)
DataGridView1.Rows(i).Cells(0).Style.Format = "dd/MM/yyyy"
texto = ""
For Each celda As System.Windows.Forms.DataGridViewCell In row.Cells
'COMPROBAMOS QUE LA CELDA NO SEA NULA, SI PERMITIMOS AÑADIR FILAS ESTO ES MUY IMPORTANTE If celda.Value IsNot Nothing Thentexto += " " & celda.Value.ToString() & " "
End If
Next
'CALCULAMOS LA POSICIÓN EN QUE SE ESCRIBE LA LÍNEAyPos = topmargin + (count * printFont.GetHeight(e.Graphics))
'ESCRIBIMOS LA LINEA CON EL OBJETO GRAPHICSe.Graphics.DrawString(texto, printFont, System.Drawing.Brushes.Black, 10, yPos)
'INCREMENTAMOS LOS CONTADOREScount += 1
i += 1
End While
'COMPROBAMOS SI QUEDAN MÁS FILAS POR IMPRIMIR, SI ES ASÍ SALDRÁN EN LA SIGUIENTE PÁGINAIf i < DataGridView1.Rows.Count Then
e.HasMorePages = True
Else
'SI LLEGAMOS AL FINAL DE HASMOREPAGES SE ESTABLECE A FALSE PRA DEJAR DE IMPRIMIRe.HasMorePages = False
'HAY QUE PONER EL CONTADOR A 0 PARA QUE NO SE QUEDE PILLADA LA VARIABLE i Y NO IMPRIMA NADA i = 0End If
End Sub
Valora esta pregunta


0
