|
-
May 28th, 2003, 08:59 AM
#1
Thread Starter
Fanatic Member
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:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim bRet As Boolean
Dim myimg As Image
Dim sAppName As String
Dim sLogo As String
Try
myimg = New Bitmap("C:\Program Files\Common Files\Microsoft Shared\Clipart\cagcat50\BD06675_.WMF")
picLogo.SizeMode = PictureBoxSizeMode.AutoSize
picLogo.Image = CType(myimg, Image)
picLogo.Refresh()
Catch ex1 As Exception
MessageBox.Show(ex1.ToString())
Finally
If Not IsNothing(myimg) Then
myimg.Dispose()
myimg = Nothing
End If
End Try
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 ...
-
May 28th, 2003, 09:14 AM
#2
PowerPoster
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:
Dim myimg as Bitmap
myimg = New Bitmap("C:\Program Files\Common Files\Microsoft Shared\Clipart\cagcat50\BD06675_.WMF")
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.
-
May 28th, 2003, 09:32 AM
#3
Thread Starter
Fanatic Member
Thanks hellswraith.
But ... I still get the error when using this:
VB Code:
dim img as Image
img = Image.FromFile("c:\image1.gif")
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 ...
-
May 28th, 2003, 10:55 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|