Print and Scale the client portion of a form

I have a form with multiple grids on it and I need to capture the form data and control and have the image scale to fit a regular 8X10 piece of paper.
I have tried using the PrintForm control that comes with the Powerpack, but there seems to be no option to scale.
I also added the pagesetupdialog, thinking that I could set the margins real small and then the whole sheet would show, but that doesn't work.
The only thing that will get the whole screen on one sheet of paper is resizing the form to make it smaller, which is something I don't want users to have to do.
What is the best way to capture a form, display it as landscape to fit on one piece of paper?
Please provide an example,
Thank you
Private Sub butPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butPrint.Click
 
        If Me.TabControl1.SelectedIndex = 2 Then 'print form
            Dim psd As New PageSetupDialog
    
            Dim ppd As New PrintPreviewDialog
            Dim Printer As New Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer
 
***'Was going to try and see if I could get the VB6.ScaleMode to work, but no luck
            'Printer.ScaleMode = Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.ScaleModeConstants.vbInches
            'Printer.ScaleLeft = -0.5
            'Printer.ScaleTop = -0.5
            'Printer.CurrentX = 0
            'Printer.CurrentY = 0
 
 
            Dim pd As New Printing.PrintDocument
            
            psd.Document = pd
            psd.PageSettings.Landscape = True
            psd.AllowMargins = True
            psd.PageSettings.Margins.Top = 0.2
          
            If psd.ShowDialog = Windows.Forms.DialogResult.OK Then
 
                Me.PrintForm1.PrinterSettings = psd.PrinterSettings
 
                If PrintForm1.PrinterSettings.IsValid Then
                    Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
 
                    Me.PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
 
                End If
            End If
            '
        End If
 
end sub

Open in new window

SheritlwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JackOfPHCommented:
Try this approach...

1.) Printscreen the form.
2.) Get the data from the clipboard then store it in an image variable.
3.) After storing it to an image file, you now have the option, of resizing the image according to the size you want.

 SendKeys.SendWait("%{PRTSC}")
 
Dim myImage as image
 
   If Not (Clipboard.GetDataObject Is Nothing) Then
      Dim data As IDataObject = Clipboard.GetDataObject
 
      If data.GetDataPresent(DataFormats.Bitmap) Then
         myImage = CType(data.GetData(DataFormats.Bitmap, True), Image)
      End If
 
   End If

Open in new window

0
JackOfPHCommented:
If you need further help, just post...
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

SheritlwAuthor Commented:
Hi,

My application is a mdi app and I don't want to print the mdi parent portion, it has panels etc on it.
I just want to print the client portion of the active mdi child.
Thanks
0
JackOfPHCommented:
Do you have screenshots of the form?
0
SheritlwAuthor Commented:
I can take a screen shot and upload it, if that will help
0
JackOfPHCommented:
Please do so...
0
SheritlwAuthor Commented:
Thanks so much for your help.
I've attached a screen shot that notes what I would like printed to a print preview screen.
Thanks again
ScreenShotBuild.jpg
0
JackOfPHCommented:

Note** the below code is the accepted sulution in this thread:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21963592.html?sfQueryTermInfo=1+10+panel+print

Put the below code in the form not in the mdi.


1. Place PrintDocument element on your form.
 
2. The complete code:
 
Public Class Form1
 
    Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
       hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
       Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
       hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
       ByVal dwRop As System.Int32) As Long
    Dim memoryImage As Bitmap
 
    Private Sub CapturePanel()
        Dim mygraphics As Graphics = Me.CreateGraphics()
        Dim s As Size = Me.Panel1.Size
        memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
        Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
        Dim dc1 As IntPtr = mygraphics.GetHdc
        Dim dc2 As IntPtr = memoryGraphics.GetHdc
        With Panel1.ClientRectangle
            BitBlt(dc2, 0, 0, .Width, .Height, dc1, Panel1.Location.X, Panel1.Location.Y, 13369376)
        End With
 
        mygraphics.ReleaseHdc(dc1)
        memoryGraphics.ReleaseHdc(dc2)
 
    End Sub
 
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
       ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
       PrintDocument1.PrintPage
        e.Graphics.DrawImage(memoryImage, 20, 20)    ' margins for printing 20, 20
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CapturePanel()
        PrintDocument1.Print()
    End Sub
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SheritlwAuthor Commented:
Well I think I finally got it working.
I believe I was having problems because of the splitcontrol and tabcontrol.  I had to make adjustments to make sure everything fit on the screen.  I also do a print preview of the screen.
I've attached the code.
Thank you very much for your help!
    Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
      hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
      Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
      hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
      ByVal dwRop As System.Int32) As Long
    Dim memoryImage As Bitmap
 
 
Private Sub butPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butPrint.Click
        If Me.TabControl1.SelectedIndex = 2 Then 'print form
            Dim ppd As New PrintPreviewDialog
 
            CaptureTab()
            PrintDocument1.DefaultPageSettings.Landscape = True
            ppd.Document = PrintDocument1
            ppd.ShowDialog()
            
        End If
        
    End Sub
 
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.Graphics.DrawImage(memoryImage, 50, 50)
    End Sub
 
  Private Sub CaptureTab()
        Dim mygraphics As Graphics = Me.CreateGraphics()
        Dim s As Size = Me.Size
        memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
        Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
        Dim dc1 As IntPtr = mygraphics.GetHdc
        Dim dc2 As IntPtr = memoryGraphics.GetHdc
        With Me.TabControl1.TabPages(2).ClientRectangle
            BitBlt(dc2, 0, 0, .Width, .Height, dc1, Me.TabControl1.TabPages(2).Location.X, Me.TabControl1.TabPages(2).Location.Y + 25, 13369376)
        End With
 
        mygraphics.ReleaseHdc(dc1)
        memoryGraphics.ReleaseHdc(dc2)
 
    End Sub

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.