473,766 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3971
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.DragEvent Args e)
{
if(e.Data.GetDa taPresent(DataF ormats.FileDrop ))
{
e.Effect=DragDr opEffects.All;
}
else
{
e.Effect=DragDr opEffects.None;
}
System.Diagnost ics.Debug.Write Line("Form1_Dra gEnter");
}

private void Form1_DragDrop( object sender,
System.Windows. Forms.DragEvent Args e)
{
string[] paths = (string[])e.Data.GetData ("FileDrop",tru e);
if (paths.Length>0 )
this.Text = paths[0];
System.Diagnost ics.Debug.Write Line("Form1_Dra gDrop");

}
</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.m icrosoft.com> wrote in message
news:BG******** ******@cpmsftng xa10.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.DragEvent Args e)
{
if(e.Data.GetDa taPresent(DataF ormats.FileDrop ))
{
e.Effect=DragDr opEffects.All;
}
else
{
e.Effect=DragDr opEffects.None;
}
System.Diagnost ics.Debug.Write Line("Form1_Dra gEnter");
}

private void Form1_DragDrop( object sender,
System.Windows. Forms.DragEvent Args e)
{
string[] paths = (string[])e.Data.GetData ("FileDrop",tru e);
if (paths.Length>0 )
this.Text = paths[0];
System.Diagnost ics.Debug.Write Line("Form1_Dra gDrop");

}
</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.m icrosoft.com> wrote in message
news:Hc******** ******@cpmsftng xa10.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
5845
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 module Dim WithEvents tc As testControl 'button1_click (for example)
1
2525
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 simple sample code - a form with a Button1, a Label1 and a Timer1. The Button1 has Tag="SomeData", the Label1 has AllowDrop=True and the Timer1 has an Interval=20.
0
1275
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 DatasetControl_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) Now I drop this Dataset Conttrol on my main form, and I also want to process
0
1322
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 methods in total are listening to the DragDrop event of the control? If I can't find out the exact number of methods listening to the DragDrop event, can I somehow remove all listeners of that event at once? I tried using m_Control.DragDrop =...
0
1018
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 does the source for the dragdrop operation know that a drop has been completed onto a valid target? And then, how does the source know what the drop target is? I've got dragdrop working within my application but I can't see any
3
3794
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 target node in the treeview and auto expand it if applicable... but after a fair bit of head scratching I can't find any easy way to accomplish this. I think what i really need is the equivalent of the HitTest method from the COM version of the...
7
4007
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 same windows running in different instances of the application the "dropped" data comes across as a system.__ComObject and I can't CType it to my class to extract the data. I've been searching for hours and haven't found any solution so I am...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.