Hej Lägg till en Button1 samt din PrintDocument kontroll till formen. Testa sedan:Printa treeview
Jag använder VB.NETs treeview i ett system och skulle nu vilja veta om någon har ett enkelt sätt att printa ut treeviewn på.
/JoakimSv: Printa treeview
Private Print_Image As Image
'This is used to take the picture
Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get a Graphics Object from the form
Dim gr As Graphics = TreeView1.CreateGraphics
'Create a bitmap from that graphics
Dim img As New Bitmap(TreeView1.Width, TreeView1.Height, gr)
'Create a Graphics object in memory from that bitmap
Dim memG As Graphics = Graphics.FromImage(img)
'get the IntPtr's of the graphics
Dim HDC1 As IntPtr = gr.GetHdc
Dim HDC2 As IntPtr = memG.GetHdc
'get the picture
BitBlt(HDC2, 0, 0, TreeView1.ClientRectangle.Width, TreeView1.ClientRectangle.Height, HDC1, 0, 0, 13369376)
'Clone the bitmap so we can dispose this one
Me.Print_Image = img.Clone()
'Clean Up
gr.ReleaseHdc(HDC1)
memG.ReleaseHdc(HDC2)
gr.Dispose()
memG.Dispose()
img.Dispose()
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'Now we draw the image to the PrintDocument's Graphics object
'the 0 and 0 are where on the page it will be printed
'0, 0 makes it print in the top left corner of the page
e.Graphics.DrawImage(Me.Print_Image, 0, 0)
End Sub