2011-04-25 4 views
-1

vb.net, VS-2010 Winform에서 패널 내용을 인쇄하는 방법.패널 내용 인쇄 방법

here 코드를 제공했지만 어떤 이유로 작동하지 않습니다.

는 내가 정확히 당신이 원하는 것을하지 않을 것 패널 내에서 컨트롤을 통해 반복 이유를 볼 패널

enter image description here

+1

내부의 양식을 인쇄하려합니다. 당신은 그것이 작동하지 않는다고 말하지만 정확히 무엇을하고 있는지 자세히 설명하지는 않습니다. 이것은 매우 기본적인 개념입니다. –

+0

@Ramhound, 예제 코드를 올려 줄 수 있습니까? –

+0

가능한 [VB.net에서 인쇄하는 방법] (http://stackoverflow.com/questions/5776452/how-to-print-in-vb-net) –

답변

1
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