title: VB.NET using bitblt to draw bitmap renders a black square
body: <p>I'm just starting out with VB.net after many years of VB 6.0 and I thought I'd get started with some graphics.</p>
  
  <p>Just for fun I'm using BitBlt to draw a bitmap I have loaded as a resource and draw it on a form. I can load an existing image from a picturebox and bitblt it, which works fine. I can also load the bitmap from resources and store it into the picturebox, but when I take the bitmap, turn it into a GDI Graphics object and BitBlt it onto the form, all I get is a black square that is the same size as the bitmap.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    Dim srcBmp As New Bitmap(Me.GetType, "colorwheel.bmp")
      Dim drect As New Rectangle(0, 0, 233, 233)
      'srcGrp = PictureBox1.CreateGraphics 'This works.
      srcGrp = Graphics.FromImage(srcBmp)     'This doesn't 
      targetGrp = Me.CreateGraphics 'destination graphics
  
      srcHdc = srcGrp.GetHdc
      TargetHdc = targetGrp.GetHdc
  
      BitBlt(TargetHdc, 0, 0, 233, 233, srcHdc, 0, 0, SRCCOPY)
  
      srcGrp.ReleaseHdc(srcHdc)
      targetGrp.ReleaseHdc(TargetHdc)
      targetGrp.Dispose()
      srcBmp.Dispose()
      srcGrp.Dispose()
  </code></pre>
  
  <p>The reasons I want to use bitblt are a) I've used it before, so it was my first choice. b) I know that it is possible to use a black and white mask to mask out some areas as transparent, which is what I need. and b) the graphics may be moving around frequently.</p>
  
  <p>Is there a better way of drawing graphics with a transparent background onto a form or picturebox? e.g. a png with an alpha channel?</p>