473,325 Members | 2,785 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,325 software developers and data experts.

Event handler or method overriding

When you create a new C# project, Visual Studio creates a main form
for you. If you double click it, the Visual Studio automatically adds
an event handler for the form's Load event. Then you can insert codes
into that method. But, you can also override the form's OnLoad method
and put that code there, which results in the same result.

Since VS.NET does in the first way, it is the recommended way? Is
there any performance differences in those two ways? Of course, like
most cases, the form will not be inherited, or accessed by other forms.
Jul 21 '08 #1
1 2228
On Sun, 20 Jul 2008 19:00:02 -0700, Sin Jeong-hun <ty*******@gmail.com>
wrote:
When you create a new C# project, Visual Studio creates a main form
for you. If you double click it, the Visual Studio automatically adds
an event handler for the form's Load event. Then you can insert codes
into that method. But, you can also override the form's OnLoad method
and put that code there, which results in the same result.

Since VS.NET does in the first way, it is the recommended way?
No, not necessarily. It's just that the VS Designer adds events, not
overrides.
Is there any performance differences in those two ways?
Negligible.

The MSDN documentation always recommends overriding methods where
possible, rather than subscribing to an event. Personally, that's what I
tend to do. But as long as you don't specifically need the added control
over execution that overriding gives you, I think it's just fine to use an
event handler instead.

Pete
Jul 21 '08 #2

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

Similar topics

8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
3
by: Steve Long | last post by:
Hello, I have a VB.NET class that raises a MapSet event that passes an argument of type interop.MapObjects2.MapClass. I have a C# class that inherits from this VB.NET class. How can I handle the...
18
by: Elder Hyde | last post by:
Hey all, A class of mine needs to tell the outside world when its buffer is not empty. The problem is that C# seems to force you to put the event-raising code in the base class. To illustrate,...
18
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
1
by: melinda | last post by:
If I have 2 classes ("A" and "B") that inherit from the same base class, and both override an event handler method HandleMyEvent(..), class "A" has a hashtable of one or more class "B"'s. When...
4
by: Rich | last post by:
Hello, I create multiple pictureboxe controls on a form in a For Loop and display thumbnail pictures. I need to add a Click event to these pictureboxes. Here is the routine that creates the...
2
by: Jayson | last post by:
Hi guys, I am using a control(I only got the dll file) downloaded from web. Whenever a key is enter it will validate the user input. If not valid it will ignore the key being enter. I want to...
9
by: DrBonzo | last post by:
Is there any effective difference between doing something in the DragDrop event handler and doing it in the OnDragDrop(.) method of a control? I'm coming from a MFC background and am having a hard...
8
by: Karsten Schramm | last post by:
Hi, when I run the following code: using System; namespace ConsoleApplication22 { class Program {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.