i will describe my problem as much possible. I have created a windows form in vb.net, having a panel, and this panel contains a canvas, the canvas has some drawn content, i want to print the canvas to pdf or whatever, my problem is not with the printer but in sending the canvas to be printed, here's some code i tried but i believe its not okay, it prints an empty page. here's some code (code is initiated by printdocument1.Print() by click of a button):
Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles printdocument1.PrintPage
Dim b As New Bitmap(pnlC.Width, pnlC.Height)
pnlC.DrawToBitmap(b, pnlC.ClientRectangle)
e.Graphics.DrawImage(b, New Point(0, 0))
For Each ctrl As Control In pnlC.Controls
If TypeOf ctrl Is Canvas Then
ctrl.Tag = Int((ctrl.Top + ctrl.Height) / printdocument1.DefaultPageSettings.Bounds.Height) + 1
e.Graphics.DrawImage(DirectCast(ctrl, PictureBox).Image, New PointF(ctrl.Left, ctrl.Top - StartPosition))
End If
Next
Dim grp As Graphics = pnlC.CreateGraphics()
Dim pnlSize As Size = pnlC.Size
bitmap = New Bitmap(pnlC.Width, pnlC.Height, grp)
grp = Graphics.FromImage(bitmap)
Dim panelLocation As Point = PointToScreen(pnlC.Location)
grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, pnlSize)
e.HasMorePages = False
End Sub
some code of whats inside the canvas:
Protected Overrides Sub drawNode(n As Node, iPosition As AbstractVector)
Dim pos As Point = GraphToScreen(TryCast(iPosition, FDGVector2))
Dim canvas As Graphics = __graphicsProvider()
Dim r As Single = n.Data.radius
SyncLock canvas
If r = 0! Then
r = If(n.Data.Neighborhoods < 30, n.Data.Neighborhoods * 9, n.Data.Neighborhoods * 7)
r = If(r = 0, 20, r)
End If
Dim pt As New Point(pos.X - r / 2, pos.Y - r / 2)
Dim rect As New Rectangle(pt, New Size(r, r))
Call canvas.FillPie(n.Data.Color, rect, 0, 360)
'Call canvas.DrawImage(n.Data.image, rect)
Call canvas.DrawString("test", New Font("Times New Roman", 12), New SolidBrush(Color.Black), pt)
End SyncLock
End Sub