Paint event not firing on usercontrol!!!

P

Peter Row

Hi,

Okay here is the setup:
- I have a Form which has 2 panels and a splitter on (options, content
panels).
- I have custom UserControl which has a panel on it and 2 buttons.
- On the above UserControl I do some painting I have tried putting it in:
- protected override void OnPaint(PaintEventArgs e)
- myControl_Paint(object sender, PaintEventArgs e)
- in constructor this.Paint += new
PaintEventHandler(myControl_Paint);
- UserControl has a resize event which calls this.Invalidate();
- I load the UserControl into one of the panels on the Form.

Problem:
Regardless of using either of the above methods the Paint event is NOT being
fired. The resize event is fired and executes this.Invalidate() with no
problems.

I have also tried setting the .ResizeRedraw property to true on the
UserControl
and then when that didn't work I also added it to the constructor of the
form
which has the panel the UserControl will be loaded into, but still nothing.

The really annoying thing is this UserControl use to function fine when I
was
first developing it as a test. Then I wrote the rest of the app, and now
that I
have come back to use my UserControl in the above scenario the Paint is just
not working. As a footnote the UserControl use to be in a class DLL now it
is in the main app .exe assembly.

Any help would be much appreciated as I'm at a complete loss.

Regards,
Peter
 
T

Tom Spink

Peter said:
Hi,

Okay here is the setup:
- I have a Form which has 2 panels and a splitter on (options, content
panels).
- I have custom UserControl which has a panel on it and 2 buttons.
- On the above UserControl I do some painting I have tried putting it in:
- protected override void OnPaint(PaintEventArgs e)
- myControl_Paint(object sender, PaintEventArgs e)
- in constructor this.Paint += new
PaintEventHandler(myControl_Paint);
- UserControl has a resize event which calls this.Invalidate();
- I load the UserControl into one of the panels on the Form.

Problem:
Regardless of using either of the above methods the Paint event is NOT
being fired. The resize event is fired and executes this.Invalidate() with
no problems.

I have also tried setting the .ResizeRedraw property to true on the
UserControl
and then when that didn't work I also added it to the constructor of the
form
which has the panel the UserControl will be loaded into, but still
nothing.

The really annoying thing is this UserControl use to function fine when I
was
first developing it as a test. Then I wrote the rest of the app, and now
that I
have come back to use my UserControl in the above scenario the Paint is
just not working. As a footnote the UserControl use to be in a class DLL
now it is in the main app .exe assembly.

Any help would be much appreciated as I'm at a complete loss.

Regards,
Peter

Hi Peter,

Try putting this line in your constructor:

this.SetStyle( ControlStyles.UserPaint, true );

(Note, this is from memory, I /think/ it's correct, but it's something along
those lines)
 
P

Peter Row

Hi,

I found various bits on Google that said exactly what you just said.
However I have done that and still nothing.
I also included the AllPaint enum value as well as the
double buffering enum value.

In further developments, the control draws at design time when
I put it on a test Form. However some times when I, for example,
cause the output window or property window to pop out in the IDE
then the control will blank out. However if I resize the design of the
form it redraws my custom UserControl correctly (it's anchored on
all sides).

At (debug) runtime it NEVER draws because OnPaint is never
called.

I am so frustrated right now it is unreal, the side of my hand is sore
from slamming it on the desk so hard.

Please code gurus out there have mercy and help put me out of
my misery.

Regards,
Peter 8-(
 

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