Hello,
Currently, I am using the code below to save the contents on a panel as an image. The thing is, all contents except for the text in the rich textbox is being saved. Can anyone help me out?
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.pnlContent.DisplayRectangle.Width + pnlContent.Padding.Left + pnlContent.Padding.Right, _
Me.pnlContent.DisplayRectangle.Height + pnlContent.Padding.Top + pnlContent.Padding.Bottom)
myGraphics = Graphics.FromImage(myBmp)
myGraphics.DrawRectangle(Pens.White, New Rectangle(0, 0,
Me.pnlContent.DisplayRectangle.Width + pnlContent.Padding.Left + pnlContent.Padding.Right * 2, Me.pnlContent.DisplayRectangle.Height + pnlContent.Padding.Top + pnlContent.Padding.Bottom * 2))
hdc = myGraphics.GetHdc
'"FormsDispPanel" is your PAnel to print
Call SendMessage(pnlContent.Handle, WM_PRINT, hdc, _
EDrawingOptions.PRF_CHILDREN Or _
EDrawingOptions.PRF_CLIENT Or _
EDrawingOptions.PRF_NONCLIENT Or _
EDrawingOptions.PRF_OWNED)
myGraphics.ReleaseHdc(hdc)
myBmp.Save(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\out.png")
myGraphics.Dispose()
myGraphics = Nothing
myBmp = Nothing
Return True
End Function
Friend WithEvents prntDoc As New PrintDocument()
Private Sub prntDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prntDoc.PrintPage
e.Graphics.DrawImage(Me.PictureBox1.Image, 0, 0)
End Sub
Thanks in Advance!
Currently, I am using the code below to save the contents on a panel as an image. The thing is, all contents except for the text in the rich textbox is being saved. Can anyone help me out?
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.pnlContent.DisplayRectangle.Width + pnlContent.Padding.Left + pnlContent.Padding.Right, _
Me.pnlContent.DisplayRectangle.Height + pnlContent.Padding.Top + pnlContent.Padding.Bottom)
myGraphics = Graphics.FromImage(myBmp)
myGraphics.DrawRectangle(Pens.White, New Rectangle(0, 0,
Me.pnlContent.DisplayRectangle.Width + pnlContent.Padding.Left + pnlContent.Padding.Right * 2, Me.pnlContent.DisplayRectangle.Height + pnlContent.Padding.Top + pnlContent.Padding.Bottom * 2))
hdc = myGraphics.GetHdc
'"FormsDispPanel" is your PAnel to print
Call SendMessage(pnlContent.Handle, WM_PRINT, hdc, _
EDrawingOptions.PRF_CHILDREN Or _
EDrawingOptions.PRF_CLIENT Or _
EDrawingOptions.PRF_NONCLIENT Or _
EDrawingOptions.PRF_OWNED)
myGraphics.ReleaseHdc(hdc)
myBmp.Save(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\out.png")
myGraphics.Dispose()
myGraphics = Nothing
myBmp = Nothing
Return True
End Function
Friend WithEvents prntDoc As New PrintDocument()
Private Sub prntDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prntDoc.PrintPage
e.Graphics.DrawImage(Me.PictureBox1.Image, 0, 0)
End Sub
Thanks in Advance!