| > The first thing I want to do is override OnPaint, and draw a line across the
| > window.
[quoted text clipped - 3 lines]
|
| You have to write the code on your own. Something like this:
Thanks for the reply. I had hoped the IDE gave some support here, as the
signatures are known by Intellisense.
<update>
It turns out that the object browser allows you to copy the nearly correct
definition (without the virtual, override, and the ^ on the arguments)
</update>
| protected:
| virtual void OnPaint(
[quoted text clipped - 8 lines]
| event, the IDE genearates an empty event handler for you automatically.
| An event handler is not an override to a virtual function.
There's both an events button (with a lightning icon) and a greenish shoebox
two icons to the right of it that has a tooltip labelled Overrides. That's
the one I was hoping would work. It's also surprising that the events are
only visible in design mode.
| In your particular case, it doesn't really make a difference if you
| handle the Paint event, or override the OnPaint virtual method. You'll
| get the same result. Just go to the Properties pane, switch to event
| mode, and double click on the Paint event in order to handle it.
I've now implemented half the drawing in both, just to see what happens.
How are you supposed to choose?
I also notice that when I resize my screen the client area is not
invalidated. It used to be possible to modify the window style at creation
to include CS_VREDRAW and CS_HREDRAW. Petzold hints at a ResizeRedraw
property, but it doesn't seem to be in the form class.
Finally, how do I call the base class in the OnPaint method without getting
carpal tunnel syndrome?
In C#, VB, or J# there's base.OnPaint(pe); MyBase.OnPaint(pe), or
super.OnPaint(pe);
Do I really have to type the following?:
System::Windows::Forms::Form::OnPaint(pevent);
Tony
Tamas Demjen - 01 Jul 2006 18:46 GMT
> Thanks for the reply. I had hoped the IDE gave some support here, as the
> signatures are known by Intellisense.
It would be nice if the IDE could generate an empty override
placeholder. I'm not sure if it can do that. However, if you press
Ctrl+Space after typing "OnPaint" (or even "On"), the IDE lists the
possible methods, and when you open the parenthesis, it shows you the
argument list.
> I've now implemented half the drawing in both, just to see what happens.
> How are you supposed to choose?
The implementation itself is nearly identical in both cases. I would
personally use events when developing an application, and overrides when
developing a reusable component/control.
> I also notice that when I resize my screen the client area is not
> invalidated. It used to be possible to modify the window style at creation
> to include CS_VREDRAW and CS_HREDRAW. Petzold hints at a ResizeRedraw
> property, but it doesn't seem to be in the form class.
You still have low level access to the CreateParams:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.createparams(d=ide
).aspx
However, I recommend using the SetStyle method:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx
What I think you need is ResizeRedraw: "If true, the control is redrawn
when it is resized." (from
http://msdn2.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx)
> Finally, how do I call the base class in the OnPaint method without getting
> carpal tunnel syndrome?
> In C#, VB, or J# there's base.OnPaint(pe); MyBase.OnPaint(pe), or
> super.OnPaint(pe);
> Do I really have to type the following?:
> System::Windows::Forms::Form::OnPaint(pevent);
__super::OnPaint(pevent);
http://msdn2.microsoft.com/en-us/library/94dw1w7x.aspx
Tom