Stampare il contenuto di una label con VBE 2005

di il
2 risposte

Stampare il contenuto di una label con VBE 2005

Ciao a tutti,

vorrei stampare il contenuto di alcune label presenti nel mio form. Attualmente riesco a stampare un testo contenuto in una stringa e attribuito ad una variabile. Ecco il codice che ho creato per la stampa:

Public Class Form1
Private WithEvents documento As New System.Drawing.Printing.PrintDocument
Private docToPrint As New Printing.PrintDocument
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InizializzaPrintViewDialog()
End Sub
Private Sub InizializzaPrintViewDialog()
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(800, 600)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(29, 29)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.UseAntiAlias = True
End Sub

Private Sub btnAnteprima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnteprima.Click
If Not (TreeView1.SelectedNode Is Nothing) Then
documento.DocumentName = TreeView1.SelectedNode.Tag
'documento.DocumentName = Campo1
PrintPreviewDialog1.Document = documento
PrintPreviewDialog1.ShowDialog()
End If
End Sub

Private Sub document_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles documento.PrintPage
Dim text As String = "Prova di stampa"
Dim printfont As New System.Drawing.Font("arial", 35, System.Drawing.FontStyle.Regular)
e.Graphics.DrawString(text, printfont, System.Drawing.Brushes.Black, 0, 0)
End Sub
End Class



Qualcuno mi sa aiutare?

2 Risposte

  • Re: Stampare il contenuto di una label con VBE 2005

    marco.voltolini ha scritto:


    Ciao a tutti,

    vorrei stampare il contenuto di alcune label presenti nel mio form. Attualmente riesco a stampare un testo contenuto in una stringa e attribuito ad una variabile. Ecco il codice che ho creato per la stampa:

    Public Class Form1
    Private WithEvents documento As New System.Drawing.Printing.PrintDocument
    Private docToPrint As New Printing.PrintDocument
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    InizializzaPrintViewDialog()
    End Sub
    Private Sub InizializzaPrintViewDialog()
    Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(800, 600)
    Me.PrintPreviewDialog1.Location = New System.Drawing.Point(29, 29)
    Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
    Me.PrintPreviewDialog1.UseAntiAlias = True
    End Sub

    Private Sub btnAnteprima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnteprima.Click
    If Not (TreeView1.SelectedNode Is Nothing) Then
    documento.DocumentName = TreeView1.SelectedNode.Tag
    'documento.DocumentName = Campo1
    PrintPreviewDialog1.Document = documento
    PrintPreviewDialog1.ShowDialog()
    End If
    End Sub

    Private Sub document_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles documento.PrintPage
    Dim text As String = "Prova di stampa"
    Dim printfont As New System.Drawing.Font("arial", 35, System.Drawing.FontStyle.Regular)
    e.Graphics.DrawString(text, printfont, System.Drawing.Brushes.Black, 0, 0)
    End Sub
    End Class



    Qualcuno mi sa aiutare?
    esistono le classi della microsoft e puoi fare il print del form
    funziona....
    ciao
  • Re: Stampare il contenuto di una label con VBE 2005

    Ciao,

    ho risolto in questa maniera:


    Public Class Form1

    Private WithEvents documento As New System.Drawing.Printing.PrintDocument
    Private docToPrint As New Printing.PrintDocument
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    InizializzaPrintViewDialog()
    'ListBox1.Visible = False

    End Sub
    Private Sub InizializzaPrintViewDialog()
    Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(800, 600)
    Me.PrintPreviewDialog1.Location = New System.Drawing.Point(29, 29)
    Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
    Me.PrintPreviewDialog1.UseAntiAlias = True
    End Sub

    Private Sub btnAnteprima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnteprima.Click
    PrintPreviewDialog1.Document = documento
    PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub document_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles documento.PrintPage
    Dim printfont As New System.Drawing.Font("verdana", 10, System.Drawing.FontStyle.Regular)
    e.Graphics.DrawString(Me.lblData.Text, printfont, System.Drawing.Brushes.Black, 0, 0)
    e.Graphics.DrawString(Me.lblOra.Text, printfont, System.Drawing.Brushes.Black, 150, 0)
    e.Graphics.DrawString(Me.lblMateriale.Text, printfont, System.Drawing.Brushes.Black, 0, 130)
    e.Graphics.DrawString(Me.lblPeso.Text, printfont, System.Drawing.Brushes.Black, 150, 130)
    End Sub

    Private Sub btnStampa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStampa.Click
    PrintDialog1.AllowSomePages = True
    PrintDialog1.Document = docToPrint
    If (PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    docToPrint.Print()
    End If

    End Sub

    Private Sub btnSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetup.Click
    PageSetupDialog1.PageSettings = New System.Drawing.Printing.PageSettings
    PageSetupDialog1.PrinterSettings = New System.Drawing.Printing.PrinterSettings
    If (PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    Dim results() As Object = New Object() {PageSetupDialog1.PageSettings.Margins, PageSetupDialog1.PageSettings.PaperSize, PageSetupDialog1.PageSettings.Landscape, PageSetupDialog1.PrinterSettings.PrinterName, PageSetupDialog1.PrinterSettings.PrintRange}
    lsbProprietàStampante.Items.Clear()
    lsbProprietàStampante.Items.AddRange(results)
    End If

    End Sub

    End Class
Devi accedere o registrarti per scrivere nel forum
2 risposte