Home All Groups Group Topic Archive Search About
Author
29 Dec 2006 10:17 PM
Roger Vale
Hi all

Visual studio 2005
Visual Basic
windows mobile application

I am getting this from the imediate window A first chance exception of type
'System.InvalidCastException' occurred in System.Drawing.dll

Now the program still runs but this error seems to appear every time i swap
an image from a file

Code i am using is as follows

Dim leftImage As Bitmap


                leftImage = New Bitmap(boardImagesPath +
CStr(boardPositionP1 - 1) + ".jpg")
                leftPb.Image = leftImage


I dont know if this is enough information any help would be great

Thanks in advance

Roger

Author
29 Dec 2006 10:30 PM
Newbie Coder
New Bitmap & you set it to JPG


Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
> Hi all
>
> Visual studio 2005
> Visual Basic
> windows mobile application
>
> I am getting this from the imediate window A first chance exception of
type
> 'System.InvalidCastException' occurred in System.Drawing.dll
>
> Now the program still runs but this error seems to appear every time i
swap
> an image from a file
>
> Code i am using is as follows
>
> Dim leftImage As Bitmap
>
>
>                 leftImage = New Bitmap(boardImagesPath +
> CStr(boardPositionP1 - 1) + ".jpg")
>                 leftPb.Image = leftImage
>
>
> I dont know if this is enough information any help would be great
>
> Thanks in advance
>
> Roger
>
Author
29 Dec 2006 11:04 PM
Stephany Young
You may see this message at when you 'debug' the project in the IDE, but you
will never see it when you compile a project.

When an application is being debugged, the debugger gets notified whenever
an exception is encountered  At this point, the application is suspended and
the debugger decides how to handle the exception. The first pass through
this mechanism is called a "first chance" exception. Depending on the
debugger's configuration, it will either resume the application and pass the
exception on or it will leave the application suspended and enter debug
mode. If the application handles the exception, it continues to run
normally.

If the application does not handle the exception, the debugger is
re-notified. This is known as a "second chance" exception. The debugger
again suspends the application and determines how to handle this exception.
Typically, debuggers are configured to stop on second chance (unhandled)
exceptions and debug mode is entered, allowing you to debug.

First chance exception messages most often do not mean there is a problem in
the code. For applications / components which handle exceptions gracefully,
first chance exception messages let the developer know that an exceptional
situation was encountered and was handled.

For code without exception handling, the debugger will receive a second
chance exception notification and will stop with a unhandled exception.

Because you are not getting an unhandled exception, (or if you are you
haven't said so), then you must have some exception handling code that you
ommitted from your post. If that is the case then you have nothing to worry
about.

By the way, are you aware that you can simply that piece of code to:

  leftPb.Load(boardImagesPath + CStr(boardPositionP1 - 1) + ".jpg")

or, even better:

  leftPb.Load(boardImagesPath & CStr(boardPositionP1 - 1) & ".jpg")


Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
> Hi all
>
> Visual studio 2005
> Visual Basic
> windows mobile application
>
> I am getting this from the imediate window A first chance exception of
> type
> 'System.InvalidCastException' occurred in System.Drawing.dll
>
> Now the program still runs but this error seems to appear every time i
> swap
> an image from a file
>
> Code i am using is as follows
>
> Dim leftImage As Bitmap
>
>
>                leftImage = New Bitmap(boardImagesPath +
> CStr(boardPositionP1 - 1) + ".jpg")
>                leftPb.Image = leftImage
>
>
> I dont know if this is enough information any help would be great
>
> Thanks in advance
>
> Roger
>
Author
29 Dec 2006 11:45 PM
Roger Vale
Thanks for the reply

I am not getting a unhandled reply and i have read that this will not cause
a problem when not running in debug mode.
But it does slow down the application while it runs in debug mode
is there any way to prevent this?

and thanks for the coding advice I did have the code the way you suggested
but have changed it arround to try and remove this first chance error



Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:OmB4o25KHHA.4376@TK2MSFTNGP03.phx.gbl...
> You may see this message at when you 'debug' the project in the IDE, but
> you will never see it when you compile a project.
>
> When an application is being debugged, the debugger gets notified whenever
> an exception is encountered  At this point, the application is suspended
> and the debugger decides how to handle the exception. The first pass
> through this mechanism is called a "first chance" exception. Depending on
> the debugger's configuration, it will either resume the application and
> pass the exception on or it will leave the application suspended and enter
> debug mode. If the application handles the exception, it continues to run
> normally.
>
> If the application does not handle the exception, the debugger is
> re-notified. This is known as a "second chance" exception. The debugger
> again suspends the application and determines how to handle this
> exception. Typically, debuggers are configured to stop on second chance
> (unhandled) exceptions and debug mode is entered, allowing you to debug.
>
> First chance exception messages most often do not mean there is a problem
> in the code. For applications / components which handle exceptions
> gracefully, first chance exception messages let the developer know that an
> exceptional situation was encountered and was handled.
>
> For code without exception handling, the debugger will receive a second
> chance exception notification and will stop with a unhandled exception.
>
> Because you are not getting an unhandled exception, (or if you are you
> haven't said so), then you must have some exception handling code that you
> ommitted from your post. If that is the case then you have nothing to
> worry about.
>
> By the way, are you aware that you can simply that piece of code to:
>
>  leftPb.Load(boardImagesPath + CStr(boardPositionP1 - 1) + ".jpg")
>
> or, even better:
>
>  leftPb.Load(boardImagesPath & CStr(boardPositionP1 - 1) & ".jpg")
>
>
> "Roger Vale" <roger.v***@btinternet.com> wrote in message
> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>> Hi all
>>
>> Visual studio 2005
>> Visual Basic
>> windows mobile application
>>
>> I am getting this from the imediate window A first chance exception of
>> type
>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>
>> Now the program still runs but this error seems to appear every time i
>> swap
>> an image from a file
>>
>> Code i am using is as follows
>>
>> Dim leftImage As Bitmap
>>
>>
>>                leftImage = New Bitmap(boardImagesPath +
>> CStr(boardPositionP1 - 1) + ".jpg")
>>                leftPb.Image = leftImage
>>
>>
>> I dont know if this is enough information any help would be great
>>
>> Thanks in advance
>>
>> Roger
>>
>
>
Author
29 Dec 2006 11:56 PM
Stephany Young
What slows down the application while it runs in debug mode is the fact that
you're running it in debug mode in the IDE.


Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:e1za0N6KHHA.536@TK2MSFTNGP02.phx.gbl...
> Thanks for the reply
>
> I am not getting a unhandled reply and i have read that this will not
> cause a problem when not running in debug mode.
> But it does slow down the application while it runs in debug mode
> is there any way to prevent this?
>
> and thanks for the coding advice I did have the code the way you suggested
> but have changed it arround to try and remove this first chance error
>
>
>
> "Stephany Young" <noone@localhost> wrote in message
> news:OmB4o25KHHA.4376@TK2MSFTNGP03.phx.gbl...
>> You may see this message at when you 'debug' the project in the IDE, but
>> you will never see it when you compile a project.
>>
>> When an application is being debugged, the debugger gets notified
>> whenever an exception is encountered  At this point, the application is
>> suspended and the debugger decides how to handle the exception. The first
>> pass through this mechanism is called a "first chance" exception.
>> Depending on the debugger's configuration, it will either resume the
>> application and pass the exception on or it will leave the application
>> suspended and enter debug mode. If the application handles the exception,
>> it continues to run normally.
>>
>> If the application does not handle the exception, the debugger is
>> re-notified. This is known as a "second chance" exception. The debugger
>> again suspends the application and determines how to handle this
>> exception. Typically, debuggers are configured to stop on second chance
>> (unhandled) exceptions and debug mode is entered, allowing you to debug.
>>
>> First chance exception messages most often do not mean there is a problem
>> in the code. For applications / components which handle exceptions
>> gracefully, first chance exception messages let the developer know that
>> an exceptional situation was encountered and was handled.
>>
>> For code without exception handling, the debugger will receive a second
>> chance exception notification and will stop with a unhandled exception.
>>
>> Because you are not getting an unhandled exception, (or if you are you
>> haven't said so), then you must have some exception handling code that
>> you ommitted from your post. If that is the case then you have nothing to
>> worry about.
>>
>> By the way, are you aware that you can simply that piece of code to:
>>
>>  leftPb.Load(boardImagesPath + CStr(boardPositionP1 - 1) + ".jpg")
>>
>> or, even better:
>>
>>  leftPb.Load(boardImagesPath & CStr(boardPositionP1 - 1) & ".jpg")
>>
>>
>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>> Hi all
>>>
>>> Visual studio 2005
>>> Visual Basic
>>> windows mobile application
>>>
>>> I am getting this from the imediate window A first chance exception of
>>> type
>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>
>>> Now the program still runs but this error seems to appear every time i
>>> swap
>>> an image from a file
>>>
>>> Code i am using is as follows
>>>
>>> Dim leftImage As Bitmap
>>>
>>>
>>>                leftImage = New Bitmap(boardImagesPath +
>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>                leftPb.Image = leftImage
>>>
>>>
>>> I dont know if this is enough information any help would be great
>>>
>>> Thanks in advance
>>>
>>> Roger
>>>
>>
>>
>
Author
30 Dec 2006 4:09 AM
Tom Leylan
You are loading a bitmap which is fine but the .Image property is of type
Image, try to DirectCast leftImage and the error should go away.
Alternatively (as Stephany pointed out) you can use Load() which takes the
string as a parameter.  I doubt that method would result in the same
warning.

leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
CStr(boardPositionP1 - 1) + ".jpg"), Image)

Tom

Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
> Hi all
>
> Visual studio 2005
> Visual Basic
> windows mobile application
>
> I am getting this from the imediate window A first chance exception of
> type
> 'System.InvalidCastException' occurred in System.Drawing.dll
>
> Now the program still runs but this error seems to appear every time i
> swap
> an image from a file
>
> Code i am using is as follows
>
> Dim leftImage As Bitmap
>
>
>                leftImage = New Bitmap(boardImagesPath +
> CStr(boardPositionP1 - 1) + ".jpg")
>                leftPb.Image = leftImage
>
>
> I dont know if this is enough information any help would be great
>
> Thanks in advance
>
> Roger
>
Author
30 Dec 2006 7:18 AM
Roger Vale
thanks for your reply

I have tried that and there is no change in the error :(

as far as Stephany idea of using load load is not a member of PictureBox
maybe that may throw some more light on the problem

Roger

Show quoteHide quote
"Tom Leylan" <tleylan@nospam.net> wrote in message
news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
> You are loading a bitmap which is fine but the .Image property is of type
> Image, try to DirectCast leftImage and the error should go away.
> Alternatively (as Stephany pointed out) you can use Load() which takes the
> string as a parameter.  I doubt that method would result in the same
> warning.
>
> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>
> Tom
>
> "Roger Vale" <roger.v***@btinternet.com> wrote in message
> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>> Hi all
>>
>> Visual studio 2005
>> Visual Basic
>> windows mobile application
>>
>> I am getting this from the imediate window A first chance exception of
>> type
>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>
>> Now the program still runs but this error seems to appear every time i
>> swap
>> an image from a file
>>
>> Code i am using is as follows
>>
>> Dim leftImage As Bitmap
>>
>>
>>                leftImage = New Bitmap(boardImagesPath +
>> CStr(boardPositionP1 - 1) + ".jpg")
>>                leftPb.Image = leftImage
>>
>>
>> I dont know if this is enough information any help would be great
>>
>> Thanks in advance
>>
>> Roger
>>
>
>
Author
30 Dec 2006 8:07 AM
Stephany Young
You're right. The PictureBox.Load method is not exposed in the Compact
Framwork.

I emphasise again that it is nothing to worry about unless it is causing an
unhandled exception to be thrown. If it is then handle it.

The 'first chance' messages only appear when you are in 'debug' and then (as
far as I am aware) only if you are running in the IDE.


Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:eedLsK%23KHHA.5104@TK2MSFTNGP06.phx.gbl...
> thanks for your reply
>
> I have tried that and there is no change in the error :(
>
> as far as Stephany idea of using load load is not a member of PictureBox
> maybe that may throw some more light on the problem
>
> Roger
>
> "Tom Leylan" <tleylan@nospam.net> wrote in message
> news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
>> You are loading a bitmap which is fine but the .Image property is of type
>> Image, try to DirectCast leftImage and the error should go away.
>> Alternatively (as Stephany pointed out) you can use Load() which takes
>> the string as a parameter.  I doubt that method would result in the same
>> warning.
>>
>> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
>> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>>
>> Tom
>>
>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>> Hi all
>>>
>>> Visual studio 2005
>>> Visual Basic
>>> windows mobile application
>>>
>>> I am getting this from the imediate window A first chance exception of
>>> type
>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>
>>> Now the program still runs but this error seems to appear every time i
>>> swap
>>> an image from a file
>>>
>>> Code i am using is as follows
>>>
>>> Dim leftImage As Bitmap
>>>
>>>
>>>                leftImage = New Bitmap(boardImagesPath +
>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>                leftPb.Image = leftImage
>>>
>>>
>>> I dont know if this is enough information any help would be great
>>>
>>> Thanks in advance
>>>
>>> Roger
>>>
>>
>>
>
Author
30 Dec 2006 8:35 AM
Roger Vale
Ok thanks for all the help and assistance

its just very annoying and just for information when I run the application
on the device the firts chance messages still appear.
and it does slow the device.
When I run standalone then you are correct the device runs at normal speed.

Once again thanks for the help

I will continue to watch this group as it appears to be well used and very
helpful

Good luck to all and Happy New Year

Roger



Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:%23nmQPm%23KHHA.3552@TK2MSFTNGP03.phx.gbl...
> You're right. The PictureBox.Load method is not exposed in the Compact
> Framwork.
>
> I emphasise again that it is nothing to worry about unless it is causing
> an unhandled exception to be thrown. If it is then handle it.
>
> The 'first chance' messages only appear when you are in 'debug' and then
> (as far as I am aware) only if you are running in the IDE.
>
>
> "Roger Vale" <roger.v***@btinternet.com> wrote in message
> news:eedLsK%23KHHA.5104@TK2MSFTNGP06.phx.gbl...
>> thanks for your reply
>>
>> I have tried that and there is no change in the error :(
>>
>> as far as Stephany idea of using load load is not a member of PictureBox
>> maybe that may throw some more light on the problem
>>
>> Roger
>>
>> "Tom Leylan" <tleylan@nospam.net> wrote in message
>> news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
>>> You are loading a bitmap which is fine but the .Image property is of
>>> type Image, try to DirectCast leftImage and the error should go away.
>>> Alternatively (as Stephany pointed out) you can use Load() which takes
>>> the string as a parameter.  I doubt that method would result in the same
>>> warning.
>>>
>>> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
>>> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>>>
>>> Tom
>>>
>>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>>> Hi all
>>>>
>>>> Visual studio 2005
>>>> Visual Basic
>>>> windows mobile application
>>>>
>>>> I am getting this from the imediate window A first chance exception of
>>>> type
>>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>>
>>>> Now the program still runs but this error seems to appear every time i
>>>> swap
>>>> an image from a file
>>>>
>>>> Code i am using is as follows
>>>>
>>>> Dim leftImage As Bitmap
>>>>
>>>>
>>>>                leftImage = New Bitmap(boardImagesPath +
>>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>>                leftPb.Image = leftImage
>>>>
>>>>
>>>> I dont know if this is enough information any help would be great
>>>>
>>>> Thanks in advance
>>>>
>>>> Roger
>>>>
>>>
>>>
>>
>
>
Author
30 Dec 2006 8:56 AM
Stephany Young
When it comes to the Compact Framework there is actually a dedicated
newsgroup:

  microsoft.public.dotnet.framework.compactframework

You might get better help there for questions relating to the Compact
Framework.


Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:eYe711%23KHHA.4848@TK2MSFTNGP04.phx.gbl...
> Ok thanks for all the help and assistance
>
> its just very annoying and just for information when I run the application
> on the device the firts chance messages still appear.
> and it does slow the device.
> When I run standalone then you are correct the device runs at normal
> speed.
>
> Once again thanks for the help
>
> I will continue to watch this group as it appears to be well used and very
> helpful
>
> Good luck to all and Happy New Year
>
> Roger
>
>
>
> "Stephany Young" <noone@localhost> wrote in message
> news:%23nmQPm%23KHHA.3552@TK2MSFTNGP03.phx.gbl...
>> You're right. The PictureBox.Load method is not exposed in the Compact
>> Framwork.
>>
>> I emphasise again that it is nothing to worry about unless it is causing
>> an unhandled exception to be thrown. If it is then handle it.
>>
>> The 'first chance' messages only appear when you are in 'debug' and then
>> (as far as I am aware) only if you are running in the IDE.
>>
>>
>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>> news:eedLsK%23KHHA.5104@TK2MSFTNGP06.phx.gbl...
>>> thanks for your reply
>>>
>>> I have tried that and there is no change in the error :(
>>>
>>> as far as Stephany idea of using load load is not a member of PictureBox
>>> maybe that may throw some more light on the problem
>>>
>>> Roger
>>>
>>> "Tom Leylan" <tleylan@nospam.net> wrote in message
>>> news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
>>>> You are loading a bitmap which is fine but the .Image property is of
>>>> type Image, try to DirectCast leftImage and the error should go away.
>>>> Alternatively (as Stephany pointed out) you can use Load() which takes
>>>> the string as a parameter.  I doubt that method would result in the
>>>> same warning.
>>>>
>>>> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
>>>> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>>>>
>>>> Tom
>>>>
>>>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>>>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>>>> Hi all
>>>>>
>>>>> Visual studio 2005
>>>>> Visual Basic
>>>>> windows mobile application
>>>>>
>>>>> I am getting this from the imediate window A first chance exception of
>>>>> type
>>>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>>>
>>>>> Now the program still runs but this error seems to appear every time i
>>>>> swap
>>>>> an image from a file
>>>>>
>>>>> Code i am using is as follows
>>>>>
>>>>> Dim leftImage As Bitmap
>>>>>
>>>>>
>>>>>                leftImage = New Bitmap(boardImagesPath +
>>>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>>>                leftPb.Image = leftImage
>>>>>
>>>>>
>>>>> I dont know if this is enough information any help would be great
>>>>>
>>>>> Thanks in advance
>>>>>
>>>>> Roger
>>>>>
>>>>
>>>>
>>>
>>
>>
>
Author
30 Dec 2006 9:07 AM
Roger Vale
Ok Thanks

I have tried there but did not get a reply but once again thanks

Roger

Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:OpzomB$KHHA.780@TK2MSFTNGP03.phx.gbl...
> When it comes to the Compact Framework there is actually a dedicated
> newsgroup:
>
>  microsoft.public.dotnet.framework.compactframework
>
> You might get better help there for questions relating to the Compact
> Framework.
>
>
> "Roger Vale" <roger.v***@btinternet.com> wrote in message
> news:eYe711%23KHHA.4848@TK2MSFTNGP04.phx.gbl...
>> Ok thanks for all the help and assistance
>>
>> its just very annoying and just for information when I run the
>> application on the device the firts chance messages still appear.
>> and it does slow the device.
>> When I run standalone then you are correct the device runs at normal
>> speed.
>>
>> Once again thanks for the help
>>
>> I will continue to watch this group as it appears to be well used and
>> very helpful
>>
>> Good luck to all and Happy New Year
>>
>> Roger
>>
>>
>>
>> "Stephany Young" <noone@localhost> wrote in message
>> news:%23nmQPm%23KHHA.3552@TK2MSFTNGP03.phx.gbl...
>>> You're right. The PictureBox.Load method is not exposed in the Compact
>>> Framwork.
>>>
>>> I emphasise again that it is nothing to worry about unless it is causing
>>> an unhandled exception to be thrown. If it is then handle it.
>>>
>>> The 'first chance' messages only appear when you are in 'debug' and then
>>> (as far as I am aware) only if you are running in the IDE.
>>>
>>>
>>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>>> news:eedLsK%23KHHA.5104@TK2MSFTNGP06.phx.gbl...
>>>> thanks for your reply
>>>>
>>>> I have tried that and there is no change in the error :(
>>>>
>>>> as far as Stephany idea of using load load is not a member of
>>>> PictureBox maybe that may throw some more light on the problem
>>>>
>>>> Roger
>>>>
>>>> "Tom Leylan" <tleylan@nospam.net> wrote in message
>>>> news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
>>>>> You are loading a bitmap which is fine but the .Image property is of
>>>>> type Image, try to DirectCast leftImage and the error should go away.
>>>>> Alternatively (as Stephany pointed out) you can use Load() which takes
>>>>> the string as a parameter.  I doubt that method would result in the
>>>>> same warning.
>>>>>
>>>>> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
>>>>> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>>>>>
>>>>> Tom
>>>>>
>>>>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>>>>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>>>>> Hi all
>>>>>>
>>>>>> Visual studio 2005
>>>>>> Visual Basic
>>>>>> windows mobile application
>>>>>>
>>>>>> I am getting this from the imediate window A first chance exception
>>>>>> of type
>>>>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>>>>
>>>>>> Now the program still runs but this error seems to appear every time
>>>>>> i swap
>>>>>> an image from a file
>>>>>>
>>>>>> Code i am using is as follows
>>>>>>
>>>>>> Dim leftImage As Bitmap
>>>>>>
>>>>>>
>>>>>>                leftImage = New Bitmap(boardImagesPath +
>>>>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>>>>                leftPb.Image = leftImage
>>>>>>
>>>>>>
>>>>>> I dont know if this is enough information any help would be great
>>>>>>
>>>>>> Thanks in advance
>>>>>>
>>>>>> Roger
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
>
Author
30 Dec 2006 9:45 AM
Tom Leylan
I can't look up the docs (or test) on the compact framework but you might
check the data type of the Image property on the PictureBox just to make
sure.  Take the picture box out of the equation (for testing purposes) and
simply try to cast the Bitmap into an Image (if that is the right datatype).
I've been using .PNG graphics but there is no reason that .JPG shouldn't
work the same.



Show quoteHide quote
"Roger Vale" <roger.v***@btinternet.com> wrote in message
news:eedLsK%23KHHA.5104@TK2MSFTNGP06.phx.gbl...
> thanks for your reply
>
> I have tried that and there is no change in the error :(
>
> as far as Stephany idea of using load load is not a member of PictureBox
> maybe that may throw some more light on the problem
>
> Roger
>
> "Tom Leylan" <tleylan@nospam.net> wrote in message
> news:uPuA7g8KHHA.780@TK2MSFTNGP03.phx.gbl...
>> You are loading a bitmap which is fine but the .Image property is of type
>> Image, try to DirectCast leftImage and the error should go away.
>> Alternatively (as Stephany pointed out) you can use Load() which takes
>> the string as a parameter.  I doubt that method would result in the same
>> warning.
>>
>> leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
>> CStr(boardPositionP1 - 1) + ".jpg"), Image)
>>
>> Tom
>>
>> "Roger Vale" <roger.v***@btinternet.com> wrote in message
>> news:uyrEtc5KHHA.5000@TK2MSFTNGP03.phx.gbl...
>>> Hi all
>>>
>>> Visual studio 2005
>>> Visual Basic
>>> windows mobile application
>>>
>>> I am getting this from the imediate window A first chance exception of
>>> type
>>> 'System.InvalidCastException' occurred in System.Drawing.dll
>>>
>>> Now the program still runs but this error seems to appear every time i
>>> swap
>>> an image from a file
>>>
>>> Code i am using is as follows
>>>
>>> Dim leftImage As Bitmap
>>>
>>>
>>>                leftImage = New Bitmap(boardImagesPath +
>>> CStr(boardPositionP1 - 1) + ".jpg")
>>>                leftPb.Image = leftImage
>>>
>>>
>>> I dont know if this is enough information any help would be great
>>>
>>> Thanks in advance
>>>
>>> Roger
>>>
>>
>>
>