PDA

Click to See Complete Forum and Search --> : Exception Handling[RESOLVED]


Rattlerr
Feb 27th, 2006, 03:59 PM
I'm working with a OnPaintBackGround and trying to Catch an PaintEventArgs e ....It has a certain format for its size that i'm trying to change but for now i'm working on Catching the Exception thats Thrown during Debug...

What i'm trying to do is too get the OnPaint onto a Picture Box that i have on my Form

Here is the Code i'm working with just cant figure out what i need to put in past the "catch" part..

protected override void OnPaintBackground(PaintEventArgs e)
{
try
{
// Draw the current background image stretched to fill the full screen
e.Graphics.DrawImage(Backgroundimage[currentImageIndex], 578, 231, Size.Width, Size.Height);
}
catch (FormatException fEx)
{
// This is what i need to fill in to catch the above problem e.Graphics.DrawImage(Backgroundimage[currentImageIndex], and so on
}

I get a "NullReference was UnHandles" it high lights the e.Graphics.DrawImage Line and in the Locals Lists the Following::
-----------------------------------------------------
this Cannot obtain value of local or argument '<this>' as it is not available at this instruction pointer, possibly because it has been optimized away. MediaViewer.Main
-------------------------------------------------

+ e {ClipRectangle = {X=0,Y=0,Width=823,Height=586}} System.Windows.Forms.PaintEventArgs

}
----------------------------------------------------

Shuja Ali
Feb 27th, 2006, 04:04 PM
When you use catch (FormatException fEx) only formatExceptions will be caught and rest will be thrown back to the calling function. So if you want other exceptions also to be caught then you will have to add another Catch Statement after the Catch catch (FormatException fEx)
{
// This is what i need to fill in to catch the above problem e.Graphics.DrawImage(Backgroundimage[currentImageIndex], and so on
}
catch (Exception aEX)
{
//Catch all other exceptions here
} Now remeber Exceptions will be caught in the order in which you have put the catch statements. I would suggest doing some reading on MSDN prior to implementing this.

Rattlerr
Feb 27th, 2006, 05:01 PM
I worked around that with using a System Exception...

What i'm trying to do is apply a neat little Transparency Form i seen in a ScreenSaver Starter Kit that comes with the VS 2005...

It uses the Paint Feature with RSS Feeds in it....Trying to Replicate it to my Project,My project isnt a ScreenSaver like its used their Starter Kit..I like the Transparent Look with that Functionality it has,just getting it to apply to my Form is what i'm working out..

Getting it Draw to a Panel and resizing its demisions :( I can RAR up the Project if someone would look at it and help me learn to Apply this Technique to a Form....U can see what i'm talking about if you Use the ScreenSaver starter Kit and just run the Debugger...Will see a white Transparent Box that scrolls threw the RSS Feed it has..