Results 1 to 8 of 8

Thread: why do I have this error?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    why do I have this error?

    I just did
    Public This as new bitmap = picturebox1.image and then this error showed up

    System.InvalidOperationException
    but it had nothing to do with that form, why is this?
    Thank you

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: why do I have this error?

    vb Code:
    1. Public Class Form1
    2.  
    3.     Public This As Bitmap
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         This = DirectCast(PictureBox1.Image, Bitmap)
    7.     End Sub
    8.  
    9. End Class

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    Re: why do I have this error?

    thanks but now I got another error.
    This: picturbox2.Image = This
    gives this error: ArgumentException was unhandled Invalid parameter
    Thanks

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: why do I have this error?

    works for me:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Public This As Bitmap
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         This = DirectCast(PictureBox1.Image, Bitmap)
    7.     End Sub
    8.  
    9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10.         PictureBox2.Image = This
    11.     End Sub
    12.  
    13. End Class

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: why do I have this error?

    I would stay away from the word 'this' on the principle of the thing. It shouldn't have any meaning in VB, but it is the same as Me in C languages.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    Re: why do I have this error?

    but how can I stop getting that error?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: why do I have this error?

    you''ll need to show us the relevant code

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: why do I have this error?

    by paying attention to what you're doing... an IMAGE object is NOT A BITMAP... that's why there is a DIRECTCAST in the code Paul posted... seriously Paul, would it KILL you to post an explanation for the code you share once in a while? It doesn't do much good when they can't follow what's going on... anyways...
    Since an Image is not a Bitmap, you can't simply assign one to the other... you have to cast or convert it somehow... in both directions. So if you have to use DirectCast to take an .Image and put it into a Bitmap object, doesn't it stand to reason that you would have to use DirectCast to take a Bitmap and put it into an .Image?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width