|
-
Jan 6th, 2003, 08:22 PM
#1
Thread Starter
Member
Here's code to print, printpreview, & pagesetup for a datagrid
Here is the code for all of those that would like to enable printPreview, PageSetup, and Print on a datagrid:
Imports System.Drawing.Printing
Private PrintPageSettings As New PageSettings()
'For PrintPreview
Private Sub PrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreview.Click
Try
PrintDocument1.DefaultPageSettings = PrintPageSettings
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'For PageSetup
Private Sub PageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PageSetup.Click
Try
PageSetupDialog1.PageSettings = PrintPageSettings
PageSetupDialog1.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'To Print
Try
PrintDocument1.DefaultPageSettings = PrintPageSettings
PrintDialog1.Document = PrintDocument1
Dim Result As DialogResult = PrintDialog1.ShowDialog
If Result = DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Also put this code in the PrintDocument _PrintPage Event:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim myArgs As New PaintEventArgs(e.Graphics, New Rectangle(New Point(0, 0), Me.Size))
Me.InvokePaint(DataGrid1, myArgs)
End Sub
Only one problem still remains : PRINTING MULTIPLE PAGES!
Last edited by Nintendo_Wizard; Jan 7th, 2003 at 09:39 PM.
-
Jan 6th, 2003, 09:53 PM
#2
PowerPoster
Is this what you want to print?
StringToPrint = DataGrid1.Text
If so, you never use the StringToPrint variable after you assign it text.
-
Jan 6th, 2003, 10:50 PM
#3
Thread Starter
Member
RESOLVED__>>SEE CODE ABOVE
Last edited by Nintendo_Wizard; Jan 7th, 2003 at 09:41 PM.
-
Aug 6th, 2004, 09:45 AM
#4
Junior Member
Noobie
Sorry for resurrecting this old thread, but it came as part of a search.
With regards to this comment:
Also put this code in the PrintDocument _PrintPage Event:
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Where do I find that i.e. the PrintDocument_PrintPage Event?
Also, is anyone aware of a way past the limitations of no multiple pages?
Thanks.
-
Aug 6th, 2004, 11:24 AM
#5
Lively Member
This is also helpfull for me, as it shows me how to print somthing :P.
-
Aug 7th, 2004, 06:13 AM
#6
Junior Member
Re: Noobie
Originally posted by Zoot
Sorry for resurrecting this old thread, but it came as part of a search.
With regards to this comment:
Where do I find that i.e. the PrintDocument_PrintPage Event?
Ok, I worked that out because I obviously hadn't placed a PrintDocument object on the page
Originally posted by Zoot
Also, is anyone aware of a way past the limitations of no multiple pages?
Thanks.
Would still like an easy no-frills solution to how to handle more than one page, however if anyone can help.
Cheers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|