DiverDan
Well-known member
Im trying to create a virtual bitmap that will have a number of labels in it from pnlDisplay and when needed, be copied to the clipboard. Im currently getting an out of memory error from this code:
What have I done wrong....this time?
Thanks,
Dan
Code:
Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
Dim bmp As Bitmap = New Bitmap(Me.pnlDisplay.Width, Me.pnlDisplay.Height, Drawing.Imaging.PixelFormat.Format16bppGrayScale)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim lbl As Control
For Each lbl In Me.pnlDisplay.Controls
If TypeOf lbl Is Label Then
If lbl.Text <> Nothing Then
g.DrawString(lbl.Text, lbl.Font, New SolidBrush(Color.Black), lbl.Location.X, lbl.Location.Y)
End If
End If
Next
pnlDisplay.BackgroundImage = bmp
g.Dispose()
Clipboard.SetDataObject(bmp, True)
Clipboard.SetDataObject(pnlDisplay.BackgroundImage, True)
End Sub
What have I done wrong....this time?
Thanks,
Dan