Came across a very ugly problem this morning that I thought I would share. Created an application that uses an form as a template for other forms to inherit from - the form contained a panel that would display a custom image with the image being set as part of the panel paint event.
This worked fine whilst loading the image directly using Image.FromFile method. However, when storing the image as an embedded resource (within a Resource File) - the inherited forms would work fine initially - but when receiving focus from say another form - the application would crash out. After some debugging, I nailed the error down to the inherited form's paint event. The error received was...
"Invalid Parameter Used"
Not particularly useful. After some searching on the web - I came across this KB Article (http://support.microsoft.com/kb/316652) which indicated that due to a bug in the GDI+ a 24-bits-per-pixel image may not load correctly. However, by converting the image to a 32-per-pixel image would resolve this issue. Well, it worked and here's what I used...
' Load the image from the resource file
HeaderImg = CType(imgManager.GetObject("YourImageName"), System.Drawing.Bitmap)
' Create a new image to the appropriate dimensions but using 32 bits
Dim newImg As New Bitmap(HeaderImg.Width, HeaderImg.Height, Imaging.PixelFormat.Format32bppPArgb)
' Create a graphic object for the new image
Dim g As Graphics = Graphics.FromImage(newImg)
' Redraw the new image
g.DrawImage(HeaderImg, 0, 0, newImg.Width, newImg.Height)
' And reset
HeaderImg = newImg
M