开发者

How to print the Contents of a Panel

开发者 https://www.devze.com 2023-02-28 07:28 出处:网络
How do I print the contents of a panel in vb.net, VS-2010 Winform. I tried the code provided here but for some reason its not working.

How do I print the contents of a panel in vb.net, VS-2010 Winform.

I tried the code provided here but for some reason its not working.

I am try开发者_StackOverflowing to print the Form inside the panel

How to print the Contents of a Panel


Declare Auto Function SendMessage Lib "user32" ( _
         ByVal hWnd As IntPtr, _
         ByVal Msg As Integer, _
         ByVal wParam As IntPtr, _
         ByVal lParam As Integer) As Integer
Private Enum EDrawingOptions As Integer
    PRF_CHECKVISIBLE = &H1
    PRF_NONCLIENT = &H2
    PRF_CLIENT = &H4
    PRF_ERASEBKGND = &H8
    PRF_CHILDREN = &H10
    PRF_OWNED = &H20
End Enum

Private Function PrintPanel()
 Const WM_PRINT As Integer = &H317

    Dim myBmp As Bitmap
    Dim myGraphics As Graphics
    Dim hdc As System.IntPtr

    myBmp = New Bitmap( _
        Me.FormsDispPanel.DisplayRectangle.Width, _
        Me.FormsDispPanel.DisplayRectangle.Height)

    myGraphics = Graphics.FromImage(myBmp)
    myGraphics.DrawRectangle(Pens.White, New Rectangle(0, 0,      
  Me.FormsDispPanel.DisplayRectangle.Width, Me.FormsDispPanel.DisplayRectangle.Height))
    hdc = myGraphics.GetHdc
  '"FormsDispPanel" is your PAnel to print
    Call SendMessage(FormsDispPanel.Handle, WM_PRINT, hdc, _
        EDrawingOptions.PRF_CHILDREN Or _
        EDrawingOptions.PRF_CLIENT Or _
        EDrawingOptions.PRF_NONCLIENT Or _
        EDrawingOptions.PRF_OWNED)

    myGraphics.ReleaseHdc(hdc)

    myBmp.Save("d:\out.bmp")

    myGraphics.Dispose()
    myGraphics = Nothing

    myBmp = Nothing
    End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消