473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

debugging OnPaint()

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
Nov 16 '05 #1
2 1770
> 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
Nov 16 '05 #2

Thanks, Rob

"Robert Jordan" <ro*****@gmx.net> wrote in message
news:cg*************@news.t-online.com...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
4
by: dominique | last post by:
Hi, In windows forms (vb.net), i use my own controls subclassed from base controls and i override the Onxxx methods. for example: Public Class MyBouton Inherits System.Windows.Forms.Button...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.