Results 1 to 4 of 4

Thread: [2005] I need help with Print Preview?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    [2005] I need help with Print Preview?

    Hi
    I don't know why I can't preview the page, this code is from PrintDocument1:
    Code:
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim horizontalprint As Single
            Dim verticalprint As Single
            horizontalprint = e.MarginBounds.Left
            verticalprint = e.MarginBounds.Top
            Dim printfont As New Font("arial", 12)
            Dim lineheightsingle As Single = printfont.GetHeight
    
    
    
            For listindexinteger As Integer = 0 To Me.StudentList.Items.Count - 1
    
                e.Graphics.DrawString(Me.StudentList.Items(listindexinteger).ToString() & Me.DepartmentList.Items(listindexinteger).ToString() & Me.MarkList.Items(listindexinteger).ToString(), printfont, Brushes.Black, horizontalprint, verticalprint)
                verticalprint += lineheightsingle
    
    
            Next listindexinteger
    
        End Sub
    and this code is in Print preview button:
    Code:
      Private Sub printbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbtn.Click
    
            PrintPreviewDialog1.ShowDialog()
    
        End Sub
    can you see the problem there I tried it before and it works I don't why it doesn't work now

    thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2005] I need help with Print Preview?

    this will work

    vb Code:
    1. Private Sub printbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbtn.Click
    2.  
    3.     ' Create the document and attach an event handler.
    4.     Dim MyDoc As New PrintDocument()
    5.     AddHandler MyDoc.PrintPage, AddressOf MyDoc_PrintPage
    6.     Dim dlgPreview As New PrintPreviewDialog
    7.     dlgPreview.Document = MyDoc
    8.     dlgPreview.WindowState = FormWindowState.Maximized
    9.     dlgPreview.Show()
    10.  
    11. end sub
    12.  
    13.  
    14. Private Sub MyDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
    15.  
    16.     Dim horizontalprint As Single  = e.MarginBounds.Left  
    17.     Dim verticalprint As Single = e.MarginBounds.Top  
    18.     Dim printfont As New Font("arial", 12)
    19.     Dim lineheightsingle As Single = printfont.GetHeight
    20.  
    21.     For listindexinteger As Integer = 0 To Me.StudentList.Items.Count - 1    
    22.         e.Graphics.DrawString(Me.StudentList.Items(listindexinteger).ToString() & Me.DepartmentList.Items(listindexinteger).ToString() & Me.MarkList.Items(listindexinteger).ToString(), printfont, Brushes.Black, horizontalprint, verticalprint)
    23.         verticalprint += lineheightsingle
    24.     Next listindexinteger
    25.  
    26.  
    27. end sub

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] I need help with Print Preview?

    Did you forget to set PirntPreviewDialog1.Document to PrintDocument1?

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    Re: [2005] I need help with Print Preview?

    oh yes I forgot to do that hehehe .. well now all codes are working fine, thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width