Print Preview control

chinkal

New member
Joined
Sep 13, 2006
Messages
2
Programming Experience
Beginner
I have created one project in vb.net.In which i have used Tab control,which has 4 tab pages.Now i want to have print preview and print of these all tab pages at 1 clicking on "Print" button on single tab page.A click on print button on any of the tab page will able to print & Preview all tab pages and controls that it includes.

Plz If Any one help me out...
Thanks.
 
Print Preview

Thank You JohnH...

I have implemented your that code but still i m facing problem.

For that i have used this code :

VB.NET:
Private Function getsnap(ByVal Cnt As Infragistics.Win.UltraWinTabControl.UltraTabPageCo ntrol) As Bitmap()
 
Dim i As Integer
Dim g As Graphics
Dim srcPoint As Point
 
a(0) = UltraTabPageControl2
a(1) = UltraTabPageControl3
For i = 0 To 1
a(i).Show()
UltraTabControl1.Tabs(i).Selected = True
 
bmp(i) = New Bitmap(a(i).Width, a(i).Height)
g = Graphics.FromImage(bmp(i))
srcPoint = Me.Location
If Not a(i).Parent Is Nothing Then
srcPoint = a(i).Parent.PointToScreen(a(i).Location)
End If
g.CopyFromScreen(srcPoint, New Point(0, 0), a(i).Size)
g.Dispose()
Next
PrintDocument1.Print()
End Function
 
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
 
For i = 0 To 1
e.Graphics.DrawImage(bmp(i), e.MarginBounds.Location)
e.HasMorePages = True
Next
e.HasMorePages = True
End Sub
I m facing problem in this code.It is displaying the same tab page on different print preview.I want to display individual tab page on different preview pages.

Plz help me out....

Thanks.
 
Last edited by a moderator:
I would leave the getsnap function from my original post as is and use it like this (using a regular TabControl, but I'm sure the Infragistic tabpage is also a Control and provide equal functionality). Here is the getsnap function re-posted since it's so cool:
VB.NET:
Private Function getsnap(ByVal ctrl As Control) As Bitmap
    Dim bmp As New Bitmap(ctrl.Width, ctrl.Height)
    Dim g As Graphics = Graphics.FromImage(bmp)
    Dim srcPoint As Point = Me.Location
    If Not ctrl.Parent Is Nothing Then
        srcPoint = ctrl.Parent.PointToScreen(ctrl.Location)
    End If
    g.CopyFromScreen(srcPoint, New Point(0, 0), ctrl.Size)
    g.Dispose()
    Return bmp
End Function
and here code getting snaps of each tabpage and displaying them in printpreview page-by-page:
VB.NET:
Private bmps As New List(Of Bitmap)
Private index As Integer
 
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button3.Click
    bmps.Clear()
    For Each tp As TabPage In TabControl1.TabPages
        TabControl1.SelectedTab = tp
        Application.DoEvents()
        bmps.Add(getsnap(tp))
    Next
    PrintPreviewDialog1.ShowDialog()
End Sub
 
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
    e.Graphics.DrawImageUnscaled(bmps(index), e.MarginBounds.Location)
    index += 1
    If index < bmps.Count Then
        e.HasMorePages = True
    Else
        index = 0
    End If
End Sub
Btw, PrintDocument1 is here assigned to PrintPreviewDialog1s Document property in Designer.
 
I am a VB novice trying to get the above to work in v1.1 and I am having difficulties with the following two lines of code:

Private bmps As New List(Of Bitmap)
For Each tp As TabPage In TabControl1.TabPages

~Thanks
 
I am a VB novice trying to get the above to work in v1.1 and I am having difficulties with the following two lines of code:

Private bmps As New List(Of Bitmap)
For Each tp As TabPage In TabControl1.TabPages

~Thanks
Well since .Net 1.1 doesn't have generics you would use ArrayList instead, when getting items out of it, be sure to cast them to Bitmap before assigning (as you're assigning) it to a variable for use.

Your For Each loop should work fine in .Net 1.1, I've done code just like it in VS 2003 (not with TabPages though, but with Strings and Integers)
 
Back
Top