1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.VerticalScroll.Value = 0
Dim img As New Bitmap(Me.Width, Me.VerticalScroll.Maximum, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(img)
Dim buffer As BufferedGraphics = BufferedGraphicsManager.Current.Allocate(g, New System.Drawing.Rectangle(0, 0, Me.Width, Me.VerticalScroll.Maximum))
buffer.Graphics.Clear(Me.BackColor)
DessineCtrl(Me, buffer)
buffer.Render(g)
img.Save("c:\img.png", Imaging.ImageFormat.Png)
End Sub
Private Sub DessineCtrl(ByVal ctrldepart As Control, ByVal buffertotal As BufferedGraphics)
For Each ctrl As Control In ctrldepart.Controls
Dim imgCtrl As New Bitmap(ctrl.Width, ctrl.Height, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(imgCtrl)
Dim b As BufferedGraphics = BufferedGraphicsManager.Current.Allocate(g, New System.Drawing.Rectangle(0, 0, ctrl.Width, ctrl.Height))
Dim p As New PaintEventArgs(b.Graphics, New System.Drawing.Rectangle(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height))
Me.InvokePaintBackground(ctrl, p)
Me.InvokePaint(ctrl, p)
b.Render(g)
buffertotal.Graphics.DrawImage(imgCtrl, ctrl.Left, ctrl.Top)
DessineCtrl(ctrl, buffertotal)
Next
End Sub |
Partager