473,237 Members | 1,246 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,237 software developers and data experts.

DragDrop event vs. OnDragDrop(.) - what's the diff?

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 time comprehending the
difference.

Thanks for your explanations . . .

Jan 10 '06 #1
9 2341
The OnDragDrop method is, in essence, a stubbed out event handler delegate
for the DragDrop event. It does nothing, unless you override it. It's there
for your convenience. If you create your own Delegate to handle the event,
you are essentially creating the same thing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .

Jan 10 '06 #2
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
The OnDragDrop method is, in essence, a stubbed out event handler delegate
for the DragDrop event. It does nothing, unless you override it. It's
there for your convenience. If you create your own Delegate to handle the
event, you are essentially creating the same thing.


Why does the VS WinForms Designer create a new delegate/event handler for
you instead of overriding these virtual methods? (Like when we double click
on a form to get a Form_Load handler).

-- Alan
Jan 10 '06 #3
Actually, this is incorrect.

The On* methods on the Control class are what are actually called when
the event is fired. If you do not call the base class implementation,
typically, the events will not get fired as well.

Overriding the method allows you to determine when the events are fired,
and perform any pre and/or post-processing that might be necessary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
The OnDragDrop method is, in essence, a stubbed out event handler delegate
for the DragDrop event. It does nothing, unless you override it. It's
there for your convenience. If you create your own Delegate to handle the
event, you are essentially creating the same thing.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .


Jan 10 '06 #4
DrBonzo,

The difference is that OnDragDrop is actually the method that is called
to fire any event handlers which are attached to the control instance. If
you override OnDragDrop, and do not call the base class implementation, the
events will not be fired.

Generally speaking, if you are deriving from the class, it would be more
efficient to create an implementation for the method, making sure to call
the base class implementation.

However, there is no designer support for this beyond what it offers for
regular overridden methods.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .

Jan 10 '06 #5
Alan,

The reason is most likely because there is nothing in the metadata
indicating that there is an association between these events and the methods
that fire them.

It would be as simple as attaching an attribute to a method (saying, in
essence, "hey, I fire event X!"), but it's up to MS to implement it.

Also, it's easier to create an empty method stub than it is to create
one with code in it (although not that hard, since it's just a call to the
base).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Alan Pretre" <no@spam> wrote in message
news:uD***************@TK2MSFTNGP09.phx.gbl...
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
The OnDragDrop method is, in essence, a stubbed out event handler
delegate for the DragDrop event. It does nothing, unless you override it.
It's there for your convenience. If you create your own Delegate to
handle the event, you are essentially creating the same thing.


Why does the VS WinForms Designer create a new delegate/event handler for
you instead of overriding these virtual methods? (Like when we double
click on a form to get a Form_Load handler).

-- Alan

Jan 10 '06 #6
I think I've read in the dox that the On* methods 'fire the event' - does
this mean that the base implementations are what actually call all the
associated event handlers?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Actually, this is incorrect.

The On* methods on the Control class are what are actually called when
the event is fired. If you do not call the base class implementation,
typically, the events will not get fired as well.

Overriding the method allows you to determine when the events are fired,
and perform any pre and/or post-processing that might be necessary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
The OnDragDrop method is, in essence, a stubbed out event handler delegate
for the DragDrop event. It does nothing, unless you override it. It's
there for your convenience. If you create your own Delegate to handle the
event, you are essentially creating the same thing.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .



Jan 10 '06 #7
DrBonzo,

In the case where you are extending Control, yes, it is. It's not a
hard and fast rule, but you can see it in MS's implementation of classes all
over the place.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
I think I've read in the dox that the On* methods 'fire the event' - does
this mean that the base implementations are what actually call all the
associated event handlers?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Actually, this is incorrect.

The On* methods on the Control class are what are actually called
when
the event is fired. If you do not call the base class implementation,
typically, the events will not get fired as well.

Overriding the method allows you to determine when the events are
fired,
and perform any pre and/or post-processing that might be necessary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
> The OnDragDrop method is, in essence, a stubbed out event handler
> delegate
> for the DragDrop event. It does nothing, unless you override it. It's
> there for your convenience. If you create your own Delegate to handle
> the
> event, you are essentially creating the same thing.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> You can lead a fish to a bicycle,
> but it takes a very long time,
> and the bicycle has to *want* to change.
>
> "DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
> news:C9**********************************@microsof t.com...
>> 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 time comprehending
>> the
>> difference.
>>
>> Thanks for your explanations . . .
>>
>
>


Jan 10 '06 #8
DrBonzo,

As MS says in their docs overriding On* method is preferable way of handling
the events in a case of ingeritanse.

Usually you hook events when you don't derive a new class in this case
overriding is not an option.

Hooking events is also a way to provide more than one hendler for an event.
--

Stoitcho Goutsev (100)

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .

Jan 10 '06 #9
Hi Nicholas,

Yes, that is correct. I wouldn't say that my answer was incorrect. It was a
simplification (note the use of the word "essentially"). However, because of
what you mentioned, using the On* methods is more efficient than wiring up
your own event handlers.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eD**************@TK2MSFTNGP12.phx.gbl...
Actually, this is incorrect.

The On* methods on the Control class are what are actually called when
the event is fired. If you do not call the base class implementation,
typically, the events will not get fired as well.

Overriding the method allows you to determine when the events are
fired, and perform any pre and/or post-processing that might be necessary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
The OnDragDrop method is, in essence, a stubbed out event handler
delegate for the DragDrop event. It does nothing, unless you override it.
It's there for your convenience. If you create your own Delegate to
handle the event, you are essentially creating the same thing.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"DrBonzo" <Dr*****@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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 time comprehending the
difference.

Thanks for your explanations . . .



Jan 10 '06 #10

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

Similar topics

8
by: Dave Wurtz | last post by:
All, Is there a way to force a derived class to contain an event. I have done this with methods (i.e. Protected MustOverride Sub Test), but can I do something similar with an event (Protected...
5
by: Peter Stojkovic | last post by:
What is the difference between the two Events Peter
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
7
by: Ben | last post by:
Hi I'm trying to setup a project that uses events. I'm creating a windows forms based application. The application interfaces to a DLL that controls a piece of external hardware, whenever an...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.