Print the entire Panel with

Good Morning! Nothing much exciting to report today except that I finally was able to automate charts to Excel for all my plans at work including the plan’s budget information. It had driven me crazy because I had turned the realization into a dollar figure instead of a percent when creating this specific to the employee. When doing the entire plan I had to turn it back into a percent and to make a long story short it wasn’t working. The good news is it is now though I have to admit it looked better when I had not included goal information in the chart and had just left it showing realization and volume.

Today’s topic is how to print an entire panel with Make it a great day!

Join me on Facebook

Imports System.Runtime.InteropServices
Public Class Form1
    Private Enum DrawingOptions
        PRF_NONCLIENT = &H2
        PRF_CLIENT = &H4
        PRF_ERASEBKGND = &H8
        PRF_CHILDREN = &H10
        PRF_OWNED = &H20
    End Enum
    Private Const WM_PRINT As Integer = &H317
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal handle As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As Integer) As IntPtr
    End Function
    Private bmp As Bitmap
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        bmp = New Bitmap(Panel1.DisplayRectangle.Width, Panel1.DisplayRectangle.Height)
        Dim G As Graphics = Graphics.FromImage(bmp)
        Dim Hdc As IntPtr = G.GetHdc()
        SendMessage(Panel1.Handle, WM_PRINT, Hdc, DrawingOptions.PRF_OWNED Or DrawingOptions.PRF_CHILDREN Or DrawingOptions.PRF_CLIENT Or DrawingOptions.PRF_NONCLIENT)
        PrintPreviewDialog1.Document = PrintDocument1
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.Graphics.DrawImage(bmp, 0, 0)
    End Sub
End Class

Join me on Facebook

Technorati Tags: ,,,,,,,,,,,,,,,,,,




  1. #1 by Sujay on March 8, 2010 - 10:25 pm

    great jobthanks dear.

  2. #2 by bluebullet77 on April 27, 2011 - 5:06 am

    first, thanks for these valuable information ,but if i want to print the content of 2 panels on 2 different pages then what is the best way to do it ????????????

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: