debugging OnPaint()

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
 
R

Robert Jordan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top