Stobber Posted August 24, 2012 Report Share Posted August 24, 2012 Can it be done? I registered for the Drag Enter? and Drop events on my subpanel, but they don't fire when I Drag onto them. The same event cases fire when linked to a string control. Quote Link to comment
Ton Plomp Posted August 25, 2012 Report Share Posted August 25, 2012 I don't have a 'Drag Enter?' event but Drag Enter is executed. However I can only drop on the border or scroll bar of the subpanel. Ton Quote Link to comment
Aristos Queue Posted August 25, 2012 Report Share Posted August 25, 2012 I am just guessing, but I'll bet this is done on purpose to avoid confusion about what happens when the subpanel is hosting a VI vs when it is not hosting a VI. Events on the subpanel tend to get routed to the VI it is hosting, so for consistency, events going to the middle of the subpanel tend to be dropped if there's nothing to receive them. In practice, it probably doesn't save you much --- I can't think of a way to make arbitrary drag-n-drop work without having two procedures, one in the host VI that handles drag-n-drop when there is no subVI hosted and another in each of the subVIs to tell the host to change. Ug. For the one in the host, I would suggest you should put a gray picture control over the top of the subpanel, use that as your drop target, and when it gets hit, hide the picture control. If you don't need to actually click on the subpanel, you could just make the picture control transparent and then leave it in play. But if you need to interact with it then any further drag-n-drop would need to be detected in the subVI. You *might* be able to make it work using "mouse enter" on the subpanel and using that to trigger unhiding the picture control. I don't know how the timing on that would work out -- unhiding a control might not cause the events chain to reevaluate its drop target. Or it might. You'd have to test. 1 Quote Link to comment
Stobber Posted August 25, 2012 Author Report Share Posted August 25, 2012 In practice, it probably doesn't save you much --- I can't think of a way to make arbitrary drag-n-drop work without having two procedures, one in the host VI that handles drag-n-drop when there is no subVI hosted and another in each of the subVIs to tell the host to change. Ug. Yeah, I need to drag data names from a tree onto different views. The two-step handler wouldn't bother me; I just need something that works for unfilled subpanels. I'll try the suggestions you gave and report back on what works. Quote Link to comment
Yair Posted August 26, 2012 Report Share Posted August 26, 2012 You *might* be able to make it work using "mouse enter" on the subpanel and using that to trigger unhiding the picture control. I'm guessing this won't work reliably, as LV tends to miss mouse events for controls if the control is thin and you go through it quickly enough (which presumably would apply fairly regularly in a SP with a picture over it. Quote Link to comment
Stobber Posted August 26, 2012 Author Report Share Posted August 26, 2012 Got it working by expanding on AQ's suggestion. Here's an incomplete example for reference. DND Subpanel (lv11).zip Quote Link to comment
Aristos Queue Posted August 26, 2012 Report Share Posted August 26, 2012 I'm guessing this won't work reliably, as LV tends to miss mouse events for controls if the control is thin and you go through it quickly enough (which presumably would apply fairly regularly in a SP with a picture over it. Except that this isn't a thin control -- you're talking about a subpanel *region* being entered. LV "misses" enter/exit events when you move quickly passed a control and the mouse is never registered as being over that control, not when the mouse actually gets registered over the region. It doesn't matter how thin the region is. I'm not surprised that Stobber got this working. Quote Link to comment
Stobber Posted August 26, 2012 Author Report Share Posted August 26, 2012 I'm not surprised that Stobber got this working. Just to clear the air, I never register for any events on the subpanel itself. I laid a transparent 2D Picture indicator over the panel and registered for Drag Enter and Drop on that. When Drag Started fires on the tree control, I make the transparent picture visible so it can fire events. When Drag Ended fires on the tree, I make the picture invisible again so it doesn't interfere with mouse clicks in the now-loaded subpanel VI. It works really well, and since I'm controlling the picture indicator's state in sync with the user's actions, there's no need to initialize anything before the container VI starts running. Quote Link to comment
Yair Posted August 27, 2012 Report Share Posted August 27, 2012 Except that this isn't a thin control -- you're talking about a subpanel *region* being entered. Now I see what you're saying. I missed that you were talking about UNhiding the control. Just so people are aware, I was talking about something like the attached VI. ...and since I'm controlling the picture indicator's state in sync with the user's actions, there's no need to initialize anything before the container VI starts running. One thing to watch out for when dealing with things like this is the VI's Mouse Leave event. In your case, this is probably less of an issue because you're inside a control and you can monitor for the drag leave event as well, but you could still be bit (for instance, if another window decides to suddenly display itself under the cursor in mid-drag or if you have an ActiveX control in the middle, which I believe still triggers a Mouse Leave event). In such cases, you could be left in an unexpected state and writing code to account for such cases (at least by restoring the FP to a safe state so you can retry) can be difficult. Mouse Enter Event.vi Quote Link to comment
Stobber Posted August 27, 2012 Author Report Share Posted August 27, 2012 One thing to watch out for when dealing with things like this is the VI's Mouse Leave event. In your case, this is probably less of an issue because you're inside a control and you can monitor for the drag leave event as well, but you could still be bit (for instance, if another window decides to suddenly display itself under the cursor in mid-drag or if you have an ActiveX control in the middle, which I believe still triggers a Mouse Leave event). In such cases, you could be left in an unexpected state and writing code to account for such cases (at least by restoring the FP to a safe state so you can retry) can be difficult. The LV Help defines the Drag Ended event: This event occurs after a drop operation, after the user cancels the drag and drop operation by pressing the <Esc> key, or the drag source window loses focus. I take this to mean it'll fire if anything unexpected happens during the drag, which is why I'm using it to decide when to hide the picture indicator. Quote Link to comment
asbo Posted August 27, 2012 Report Share Posted August 27, 2012 I think Yair's warning is more that you can't assume that the drag completed successful on that event; only that the drag completed. Quote Link to comment
Stobber Posted August 27, 2012 Author Report Share Posted August 27, 2012 That's fine; if the drag fails or is canceled, the subpanel won't load a new subVI and the picture indicator will hide itself. The user can try again if they want. Quote Link to comment
Yair Posted August 27, 2012 Report Share Posted August 27, 2012 Actually, I never really had a chance to work with the drag events, so I didn't know that they handled this. With other event such as a mouse down followed by a mouse up handling such cases can be more problematic and I guess NI learned from the problem with the older events (or that something like that is easier for drag events). Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.