none
Drucken über Vorschau RRS feed

  • Frage

  • guten abend,

    ich habe mal eine Druckvorschau programmiert(umfangreich) aber mein quellcode ist verlustig:-(

     

    die Links online ond setup links in der spalte gehn nur mit IE

    genau das gleiche will ich nei erstellen und hänge seit tage am anfang rum:(

    Imports System.Drawing.Graphics
    Public Class Form1
        Dim z As Graphics = CreateGraphics()
        Dim stift As New Pen(Color.Red, 2)
    
        ' PrintDocument-Objekt
        Dim WithEvents pDocument As New Printing.PrintDocument
        'PrintPreviewDialog
        Dim WithEvents pDialog As New PrintPreviewDialog
        Private Sub Button1_Click(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles Button1.Click
    
            pDialog.Document = pDocument
            ' Größe des Seitenvorschaufensters auf 800x600 festlegen
            pDialog.Width = 800
            pDialog.Height = 600
            pDialog.Top = 0
            pDialog.Left = 0
            z.DrawLine(stift, 100, 40, 100, 60)
            Zeichnen(z)
            ' Vorschau anzeigen
            pDialog.ShowDialog()
        End Sub
        Private Sub Zeichnen(ByVal z As Graphics)
            Dim Ft As New Font("Arial", 20)
            z.DrawRectangle(Pens.Blue, 110, 110, 115, 30)
            Dim s As String = Date.Now.ToString("HH:mm:ss")
            z.DrawString(s, Ft, Brushes.Red, 110, 110)
        End Sub
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Zeichnen(z)
            z.DrawLine(stift, 100, 110, 100, 60)
        End Sub
    End Class
    

    die vorschau zeigt eben nur weisses blatt, was muss ich da bei button1_cklick einfüegen?

    so dass:

    z.DrawLine(stift, 100, 40, 100, 60)

     

    Zeichnen(z)

     

    'Vorschau anzeigen

    pDialog.ShowDialog()

    in der vorschau die linie angezeigt wird ?

    danke gruss roland


    rk
    Samstag, 19. November 2011 17:25

Antworten

  • Zeichnen mußt du im PrintPage Ereignis des Dokuments, etwa so ...

        Private WithEvents pDocument As Printing.PrintDocument
        Private stift As New Pen(Color.Red, 2)
    
        Private Sub pDocument_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles pDocument.PrintPage
            Zeichnen(e.Graphics)
            e.Graphics.DrawLine(stift, 100, 110, 100, 60)
        End Sub
    
        Private Sub Zeichnen(ByVal z As Graphics)
            Dim Ft As New Font("Arial", 20)
            z.DrawRectangle(Pens.Blue, 110, 110, 115, 30)
            Dim s As String = Date.Now.ToString("HH:mm:ss")
            z.DrawString(s, Ft, Brushes.Red, 110, 110)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim pDialog As New PrintPreviewDialog
            pDocument = New Printing.PrintDocument
    
            pDialog.Width = 800
            pDialog.Height = 600
            pDialog.Top = 0
            pDialog.Left = 0
            pDialog.Document = pDocument
            pDialog.ShowDialog()
        End Sub
    


    Montag, 21. November 2011 12:36

Alle Antworten

  • Zeichnen mußt du im PrintPage Ereignis des Dokuments, etwa so ...

        Private WithEvents pDocument As Printing.PrintDocument
        Private stift As New Pen(Color.Red, 2)
    
        Private Sub pDocument_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles pDocument.PrintPage
            Zeichnen(e.Graphics)
            e.Graphics.DrawLine(stift, 100, 110, 100, 60)
        End Sub
    
        Private Sub Zeichnen(ByVal z As Graphics)
            Dim Ft As New Font("Arial", 20)
            z.DrawRectangle(Pens.Blue, 110, 110, 115, 30)
            Dim s As String = Date.Now.ToString("HH:mm:ss")
            z.DrawString(s, Ft, Brushes.Red, 110, 110)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim pDialog As New PrintPreviewDialog
            pDocument = New Printing.PrintDocument
    
            pDialog.Width = 800
            pDialog.Height = 600
            pDialog.Top = 0
            pDialog.Left = 0
            pDialog.Document = pDocument
            pDialog.ShowDialog()
        End Sub
    


    Montag, 21. November 2011 12:36
  • Hallo roland_k,

    Hat Dir die Antwort geholfen?

    Grüße,
    Robert

    Mittwoch, 23. November 2011 08:56
    Moderator
  • Hallo roland_k,

    Ich gehe davon aus, dass die Antwort Dir weitergeholfen hat.
    Solltest Du noch "Rückfragen" dazu haben, so gib uns bitte Bescheid.

    Grüße,
    Robert

    Freitag, 2. Dezember 2011 12:50
    Moderator
  • Hi Robert,

    sorry wenn ich erst heute antworte,

    ich habe das total neu aufgebaut,

    danke Gruss roland

    PS: ich bin 64 Jahre, mein code sollte nur ergänzt werden, so dass in der vorschau eine linie gezeichnet wird.


    rk
    Montag, 5. Dezember 2011 06:43