locked
BitBlt

    Question


  • I tried various ways, but I can't find out what is wrong!


    Today I got a message telling me “It is not possible acess an eliminated object. Object's name: Form1”


    I have a Form, a PictureBox and a Button.


    I want to try to draw a bitmap from a PictureBox to a Form.


    Here is my actual code:


    Public Class Form1



    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



    Me.Dispose()


    BitBlt(Me.Handle, 0, 0, PictureBox1.ClientRectangle.Width, PictureBox1.ClientRectangle.Height, PictureBox1.Handle, 0, 0, PictureBox1.Image.Clone)




    End Sub

    End Class


    Monday, June 18, 2007 10:11 PM

Answers

  • Don't call Me.Dispose.

     

    Dispose frees all resources for an object, so at the moment when you click the button, you destroy the form...

    Monday, June 18, 2007 10:31 PM
  • There is no reason to use the Windows API here.  This code is equivalent:

    Code Snippet

          Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

                e.Graphics.DrawImage(Picturebox1.image, 0, 0)

          End Sub

     

    Tuesday, June 19, 2007 8:52 AM

All replies

  • Don't call Me.Dispose.

     

    Dispose frees all resources for an object, so at the moment when you click the button, you destroy the form...

    Monday, June 18, 2007 10:31 PM
  • There is no reason to use the Windows API here.  This code is equivalent:

    Code Snippet

          Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

                e.Graphics.DrawImage(Picturebox1.image, 0, 0)

          End Sub

     

    Tuesday, June 19, 2007 8:52 AM