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

DragDrop question

When I play with DragDrop of files to a form I get two DragEnter events
before the DragDrop event, why is this??
Owe
Nov 16 '05 #1
4 3936
Hi Owe,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that when you do a drag drop from a
windows explorer folder onto the form, the Drag_Enter event will be fired
twice before the Drag_Drop fired.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I can not reproduce the problem, here is my reproduce code.(I tested on
windows xp+sp1, vs.net 2003)
<code snippet>
private void Form1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect=DragDropEffects.All;
}
else
{
e.Effect=DragDropEffects.None;
}
System.Diagnostics.Debug.WriteLine("Form1_DragEnte r");
}

private void Form1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
string[] paths = (string[])e.Data.GetData("FileDrop",true);
if (paths.Length>0)
this.Text = paths[0];
System.Diagnostics.Debug.WriteLine("Form1_DragDrop ");

}
</code snippet>

You may try to create a new windows application and set the AllowDrop
property to true, and then add two event handlers, one is the dragenter,
the other is dragdrop.
Try to make a test to see if you can reproduce the problem, or can you
simplied your code to reproduce the problem and post here?
Or you may try to see if you have advised the dragenter event twice which
may cause the problem.

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #2
I noticed one diff in your suggestion against my code - I'm doing
MessageBox.Show("DragEnter") and MessageBox.Show("DragDrop") respectively.
That is the difference, if I use MessageBox I get two DragEnter events - any
clue to why thata happens??

Owe


""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:BG**************@cpmsftngxa10.phx.gbl...
Hi Owe,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that when you do a drag drop from a
windows explorer folder onto the form, the Drag_Enter event will be fired
twice before the Drag_Drop fired.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I can not reproduce the problem, here is my reproduce code.(I tested on
windows xp+sp1, vs.net 2003)
<code snippet>
private void Form1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect=DragDropEffects.All;
}
else
{
e.Effect=DragDropEffects.None;
}
System.Diagnostics.Debug.WriteLine("Form1_DragEnte r");
}

private void Form1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
string[] paths = (string[])e.Data.GetData("FileDrop",true);
if (paths.Length>0)
this.Text = paths[0];
System.Diagnostics.Debug.WriteLine("Form1_DragDrop ");

}
</code snippet>

You may try to create a new windows application and set the AllowDrop
property to true, and then add two event handlers, one is the dragenter,
the other is dragdrop.
Try to make a test to see if you can reproduce the problem, or can you
simplied your code to reproduce the problem and post here?
Or you may try to see if you have advised the dragenter event twice which
may cause the problem.

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #3
Hi Owe,

If we show the messagebox in the DragEnter and DragDrop, the focus will be
switched between the windows application and the messagebox.
When we drag a file onto the form , the DragEnter will be fired, and in the
meantime, the messagebox will got the focus, if we move the mouse outside
the form's area, the mouse_leave event will be fired, and after we click
the Ok button of the messagebox, the focus will be switch back to the form,
and now the form think another drag_enter fired.

You may make a test, if we show the form and move it in the center of the
desktop, so that when the messagebox is shown, it is right above the form.
And then when we click the ok button of the messagebox, the mouse_leave
event will not be fired, and now the drag_enter will not be fired twice.

If you use the Spy++ shipped with VS.NET to spy on the Form window, you
will find that what had happened.

So I do not think that we show a messagebox in a dragenter will be a good
practice, because this will cause the focus switch which will messy the
default behavior.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #4
That is absolutely fine with me, have no need for that MessageBox - just had
it for a test and did not realize that it would have that effect.
Thank you for your explanation.
Owe

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:Hc**************@cpmsftngxa10.phx.gbl...
Hi Owe,

If we show the messagebox in the DragEnter and DragDrop, the focus will be
switched between the windows application and the messagebox.
When we drag a file onto the form , the DragEnter will be fired, and in the meantime, the messagebox will got the focus, if we move the mouse outside
the form's area, the mouse_leave event will be fired, and after we click
the Ok button of the messagebox, the focus will be switch back to the form, and now the form think another drag_enter fired.

You may make a test, if we show the form and move it in the center of the
desktop, so that when the messagebox is shown, it is right above the form.
And then when we click the ok button of the messagebox, the mouse_leave
event will not be fired, and now the drag_enter will not be fired twice.

If you use the Spy++ shipped with VS.NET to spy on the Form window, you
will find that what had happened.

So I do not think that we show a messagebox in a dragenter will be a good
practice, because this will cause the focus switch which will messy the
default behavior.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #5

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

Similar topics

7
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form...
1
by: KS | last post by:
In want to visualy drag a Button to a Label and when I depress the mousebutton on top of the label I want to show some dato from the Button in a MsgBox - that's my primary goal. I have made a...
0
by: | last post by:
I create an user control (combined form with many controls) where I process the private void DatasetControl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) private void...
0
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many...
0
by: Gene Hubert | last post by:
Well, it seems fundamental to me anyway. Hopefully it is simple enough. The question is for when the source for the dragdrop is a different application that the target for the dragdrop. How...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
7
by: JohnR | last post by:
I am using dragdrop to drag and drop a custom class instance. When I drag/drop from one window to another window in the same application everything works fine. But when trying to move between the...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.