【问题标题】:How to print the Contents of a Panel如何打印面板的内容
【发布时间】:2011-04-25 12:47:50
【问题描述】:

如何在vb.net,VS-2010 Winform中打印面板的内容。

我尝试了here 提供的代码,但由于某种原因它不起作用。

我正在尝试在面板内打印表单

【问题讨论】:

  • 我认为循环通过面板中的控件不会完全符合您的要求。你说它不工作,但不详细说明它到底在做什么。这是一个非常基本的概念......
  • @Ramhound,你能提供一个示例代码吗?
  • How to Print in VB.net的可能重复
  • 嘿,停止投票,如果我的代表低于 10,那么我将无法在我的问题中上传图片。
  • 嘿,不要再发重复的问题了。如果您发布的问题太多,您将根本无法发布问题。更好的策略是返回并编辑您的原始问题以包含新信息和更好的图像。

标签: vb.net winforms printing


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多