Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Dragacceptfiles on a form with multiple controls....

Posted on 2006-10-31
11
357 Views
Last Modified: 2008-02-01
i have a form with multiple textboxes, listboxes and command buttons. now the requirement is if i drag and drop file(s) from 'windows explorer', how can i get the OleDragDrop event of the form triggerred regardless of where the users 'drops' the files [i.e regardless of on which control the user releases the mouse]
0
Comment
Question by:expertfan
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842120
For the controls oledragdrop event, just call the form oledragdrop event

Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_OLEDragDrop data, effect, button, shift, x, y
End Sub


0
 

Author Comment

by:expertfan
ID: 17842139
no i don't want to code in every controls oledgradrop event, i am looking for a generic solution so that it can handled at a common place like 'forms oledragdrop event'
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842732
This is an unfortunate limitation of VB6...there isn't any way to make global event handlers (other than control arrays consisting of the same type of control) except by adding code all over the place.

If you want dynamic event handling then move on up to VB.Net....
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:expertfan
ID: 17842755
really???

can't we handle the oledragdrop on a form if the drop happens on the controls on the form.....i hope someone should have a workaround.
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842791
What is wrong with the sample I gave you? It is not adding any work to you other then copy and paste this "Form_OLEDragDrop data, effect, button, shift, x, y" for all controls. If you have over 100 hundred controls, this will take few minutes. If you still don't want to do this then move up to VB.Net as idle mind suggested.  

If you drop on a text box, the form oledragdrop event is not fired so no, it will not work. that is why I suggested to call the routine from each control.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842793
"can't we handle the oledragdrop on a form if the drop happens on the controls on the form"

Yes you can...

lunchbyte gave you that solution already:

    Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
        Form_OLEDragDrop data, effect, button, shift, x, y
    End Sub

The drop above is occuring in the "text" control and he is then passing that info along to the forms OLEDragDrop "event handler" sub.

Of course you have to do this for every control that you want "passed on"!

There may be a solution using subclassing...would have to go searching...
0
 

Author Comment

by:expertfan
ID: 17842812
yes my current code is exactly what you said, every control i have the oledragdrop event coded :)

i am looking for a better solution.
0
 
LVL 2

Accepted Solution

by:
quarkphoton earned 500 total points
ID: 17842886
this can be done using subclassing....

http://www.vbcodemagician.dk/resources/dragcomponent.htm
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842904
Found a subclassing example by wpsjr1 here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11678998.html#4945622

A quick test allowed the drop to be made on any control on the form.

I just changed the Forms code to hook the form instead of a flexgrid:

Option Explicit

Private Sub Form_Load()
  DragAcceptFiles Me.hwnd, 1   ' begin accepting
  Hook Me.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
  UnHook Me.hwnd
  DragAcceptFiles Me.hwnd, 0   ' stop accepting
End Sub
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 17848628
If you have multiple dropped files you can use this routine, same as Idle Minds except that example will only throw out the first dropped file in the buffer.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22010741.html
0
 

Author Comment

by:expertfan
ID: 17878680
thanks quarkphoton!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question