Results 1 to 4 of 4

Thread: PictureBox error when Form_Activated is fired

  1. #1

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    PictureBox error when Form_Activated is fired

    Hi

    I am getting an error when I minimize and maximize a form where I dynamically load a picture box. Here's the code:

    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         Dim bRet As Boolean
    3.         Dim myimg As Image
    4.         Dim sAppName As String
    5.         Dim sLogo As String
    6.  
    7.         Try
    8.  
    9.             myimg = New Bitmap("C:\Program Files\Common Files\Microsoft Shared\Clipart\cagcat50\BD06675_.WMF")
    10.             picLogo.SizeMode = PictureBoxSizeMode.AutoSize
    11.             picLogo.Image = CType(myimg, Image)
    12.             picLogo.Refresh()
    13.  
    14.         Catch ex1 As Exception
    15.             MessageBox.Show(ex1.ToString())
    16.         Finally
    17.             If Not IsNothing(myimg) Then
    18.                 myimg.Dispose()
    19.                 myimg = Nothing
    20.             End If
    21.         End Try
    22.  
    23.     End Sub

    Before I load the image by clicking the button I can minimize and maximize my form. However, when I load the image in the picturebox, minimize the form and maximize I get the following error popping up:


    An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

    Additional information: Invalid parameter used


    I get a much longer error message when running the compiled code.

    Can anyone help please.

    Thanks
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I am not sure, but I did find somthing for you:
    picLogo.Image = CType(myimg, Image)

    You don't need to convert the bitmap object into a image object, you can just do this:
    VB Code:
    1. Dim myimg as Bitmap
    2. myimg = New Bitmap("C:\Program Files\Common Files\Microsoft Shared\Clipart\cagcat50\BD06675_.WMF")
    3. picLogo.Image = myimg

    The reason why is because a Bitmap object is derived from the Image object. It supports all the memebers of the image object, so it can be used in place of where an image object can be used.

  3. #3

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Thanks hellswraith.

    But ... I still get the error when using this:

    VB Code:
    1. dim img as Image
    2.  
    3.    img = Image.FromFile("c:\image1.gif")
    4.    picLogo.image = img

    On another note, when I run the compiled code it seems to err around the OnPaint event of the picturebox. Do i have to handle anything when dynmically loading images in a picture box?
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm what did that have to do with Form_Activated? do yuo have a code for the onPaint event? Just remember that the width and height of the form is zero when it's minimized. Are you doing anything in form_resize or in onpaint?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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