debugging OnPaint()

  • Thread starter Thread starter Marge Inoferror
  • Start date Start date
M

Marge Inoferror

I'm drawing images to scale based on the size of the window. I have my
calls to DrawImage in an OnPaint override. I use Visual C#.NET.

It repaints just fine when the window is resized. It does not repaint when
the window gets covered by another window and then uncovered. It then
errors on the next resize.

Here is the error:

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an
object.
at TouchTalk.Form1.OnPaint(PaintEventArgs e) in
g:\g\touchtalk\form1.cs:line 232


Here is the beginning of OnPaint:

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics dc = e.Graphics;

int windowWidth;
int windowHeight;
int pictureWidth;
int pictureHeight;
int xOrigin;
int yOrigin;

Form formSize = Form.ActiveForm;
windowWidth = formSize.Width; // line 232
windowHeight = formSize.Height
....


If you could clue me in as to the error of my ways, I'd be grateful...

Thanks,
Marge
 
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics dc = e.Graphics;

int windowWidth;
int windowHeight;
int pictureWidth;
int pictureHeight;
int xOrigin;
int yOrigin;

Form formSize = Form.ActiveForm;

there is no ActiveForm when your app is not activated!
windowWidth = formSize.Width; // line 232
windowHeight = formSize.Height
...

bye
rob
 
Back
Top