473,395 Members | 1,393 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.

How Do I Add Overrides to a form?

I created a new Windows Forms Application, with a blank form.

The first thing I want to do is override OnPaint, and draw a line across the
window.

I can't for the life of me figure out how I'm supposed to do this with
Visual Studio.

If I go to the class view, and click on form1 a bunch of properties show up
for the form, but if I click on either the events button in the properties
window, or the Messages or the Override button, the pane is blank.

Right clicking the class name in Class View allows me to Add, but I have to
figure out the prototype by hand.

If I click on the form in design view, all of the events show up in the
properties window, but I still don't get any overrides, despite the button
being enabled.

Is there a way to do this (there must be surely). VC 6 made this so easy.

Please, someone help!

Tony

Jun 30 '06 #1
3 1734
A Wieser wrote:
The first thing I want to do is override OnPaint, and draw a line across the
window.

I can't for the life of me figure out how I'm supposed to do this with
Visual Studio.
You have to write the code on your own. Something like this:

protected:
virtual void OnPaint(
/* whatever arguments the method has */
) override;
If I click on the form in design view, all of the events show up in the
properties window, but I still don't get any overrides, despite the button
being enabled.


That's not an override, but an event handler. If you double click on an
event, the IDE genearates an empty event handler for you automatically.
An event handler is not an override to a virtual function.

Typically when you create custom controls, you subclass the control,
creating your own class, and override the required virtual method.
However, when you design an application form, you simply handle the
events of the controls on the form.

For example, a Button is capable of firing the Click event, without
knowing which method is going to handle it. All you have to do is double
click on the Click event, and the IDE binds your Button1Click handler
method to the Button1->Click event.

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.

Tom
Jun 30 '06 #2
"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:ea**************@TK2MSFTNGP03.phx.gbl...
| > The first thing I want to do is override OnPaint, and draw a line across
the
| > window.
| >
| > I can't for the life of me figure out how I'm supposed to do this with
| > Visual Studio.
|
| 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(
| /* whatever arguments the method has */
| ) override;
|
| > If I click on the form in design view, all of the events show up in the
| > properties window, but I still don't get any overrides, despite the
button
| > being enabled.
|
| That's not an override, but an event handler. If you double click on an
| 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

Jul 1 '06 #3
A Wieser wrote:
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/lib...ms(d=ide).aspx

However, I recommend using the SetStyle method:
http://msdn2.microsoft.com/en-us/lib....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/lib...rolstyles.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
Jul 1 '06 #4

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

Similar topics

3
by: ECVerify.com | last post by:
I posted this earlier but never got a response...so I am trying again **************************** Hey everyone, I have a simple (I hope question) To get the events in C# I can go to the...
4
by: Christopher W. Douglas | last post by:
I am developing a VB.NET app using Visual Studio.NET 2003. VB.NET allows me to create a class with two or more methods that have the same name, as long as they have different (non-optional)...
5
by: ECVerify.com | last post by:
This should be a basic question. In VB.NET in the two drop downs over the source code for a form you can get a list of the events and overrides for that form. In VC++ in the properties window...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
4
by: Charles Law | last post by:
In a form, there is a set of events that can be handled. There is also a list of (Overrides). So, for the Closed event, for example, there is an override OnClosed. Where should exit code be...
3
by: Iouri | last post by:
I have added the Overrides proc onMouseMove like Protected Overrides Sub onMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs) ........... End Sub This proc supposed to fire when I...
9
by: Surrealist | last post by:
I need something likes as when I create an event procedure. I can use top-left and top-right dropdown list of code editor to select object and its exposed events respectively. Then, the IDE,...
0
by: A Wieser | last post by:
I created a new Windows Forms Application, with a blank form. The first thing I want to do is override OnPaint, and draw a line across the window. I can't for the life of me figure out how I'm...
2
by: Matt Brown - identify | last post by:
Hello, I'm very new to this level of programming and .net in general. My background is VB. I am attempting to use the WebBrowser control to load a flash movie, and it is a known issue...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.