R
raylopez99
See comment below. This is a simple problem but I'm a little rusty.
How to break out of a event loop (here _Paint)? I've tried if/else,
case, etc but not quite what I want--I keep getting the JIT system
event exception handler saying "zero area!", or, worse, the Paint loop
refuses to run at all; what I want to do is simply break out of the
_Paint loop, and (optionally) show a MessageBox.
This error happens everytime the "this.ClientRectange" of the window
being painted becomes zero, that is, everytime this window is
minimized.
So one way around this (perhaps the solution to this problem) is to
set up code so that when a window is minimized, _Paint() is not
executed. Or is there a simplier way?
RL
private void Form2MyDialogBox_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = this.ClientRectangle;
int cx = rect.Width;
int cy = rect.Height;
bool TrueOrFalseZeroRect;
if ((cx != 0) || (cy !=0)) { TrueOrFalseZeroRect = false; } else
{ TrueOrFalseZeroRect = true; throw new ArgumentException("zero
area!"); }
// AT THIS POINT IN PAINT, IF THE RECT IS ZERO AREA, I WOULD LIKE TO
BREAK OUT OF PAINT...THE BELOW TRY/CATCH DOESN'T WORK
try
{
// stuff deleted here, not important, basically you get a divide by
zero error when cx=0
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
brush.Dispose(); //clean up brush resources
}
}
How to break out of a event loop (here _Paint)? I've tried if/else,
case, etc but not quite what I want--I keep getting the JIT system
event exception handler saying "zero area!", or, worse, the Paint loop
refuses to run at all; what I want to do is simply break out of the
_Paint loop, and (optionally) show a MessageBox.
This error happens everytime the "this.ClientRectange" of the window
being painted becomes zero, that is, everytime this window is
minimized.
So one way around this (perhaps the solution to this problem) is to
set up code so that when a window is minimized, _Paint() is not
executed. Or is there a simplier way?
RL
private void Form2MyDialogBox_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = this.ClientRectangle;
int cx = rect.Width;
int cy = rect.Height;
bool TrueOrFalseZeroRect;
if ((cx != 0) || (cy !=0)) { TrueOrFalseZeroRect = false; } else
{ TrueOrFalseZeroRect = true; throw new ArgumentException("zero
area!"); }
// AT THIS POINT IN PAINT, IF THE RECT IS ZERO AREA, I WOULD LIKE TO
BREAK OUT OF PAINT...THE BELOW TRY/CATCH DOESN'T WORK
try
{
// stuff deleted here, not important, basically you get a divide by
zero error when cx=0
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
brush.Dispose(); //clean up brush resources
}
}