Update virtual bmp and save to clipboard

DiverDan

Well-known member
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
User Rank
*Experts*
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:

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
 
Thanks Hamburger1984, That did it!!!

Now whats with the BLUE background??

It reads RGB 0, 0, 211 but bmp.MakeTransparent(Color.FromArgb(0, 0, 211)) doesnt seem to have any effect. Any thoughts??

Dan
 
Last edited by a moderator:
Back
Top