WaitCursor and mouse locked in QueryContinueDrag

G

Guest

While developing a drag&drop enabled application I found out this
"strange" behaviour: if I put a message box into the QueryContinueDrag
event handler the message box is shown but the mouse cursor is set to
WaitCursor (Hourglass) and I can't click on OK or on X, so that the
only way to close the message box is via the keyboard, by pressing
SPACE key.

The most strange thing is that if I place two message boxes, only the
first one is affected by the issue described: it seems that the
unloading of the first message box someway "resets" the mouse.


The steps to reproduce this are simple:


1) Create a new Windows Forms Project
2) Place a ListView control on the form
3) Paste the following code:


====8<===CODE================================


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


ListView1.View = View.List
ListView1.Items.Add("test")


End Sub


Private Sub ListView1_ItemDrag(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag


If e.Button = Windows.Forms.MouseButtons.Left Then
ListView1.DoDragDrop("something to drag",
DragDropEffects.Move)
End If


End Sub


Private Sub ListView1_QueryContinueDrag(ByVal sender As Object,
ByVal e As System.Windows.Forms.QueryContinueDragEventArgs) Handles
ListView1.QueryContinueDrag


If e.Action = DragAction.Drop Then
MsgBox("First Message") 'press SPACEBAR to hide this
MsgBox("Second message") 'this can be hidden the usual
way
End If


End Sub


====8<===CODE - END==========================


4) Run the application
3) Try to drag&drop the "test" item somewhere


I'm using Visual Studio 2005 ver. 8.0.50727.42


Any Suggestion?


Thanks


Roberto
 
T

tommaso.gastaldi

I have the same version. There is no difference between the 2 msgboxes:
I need to press enter in either case.

Tommaso

Roberto Reale ha scritto:
 
G

Guest

I finally worked it out!

I found out that when QueryContinueDrag is fired, mouse control is not
automatically given to the form. This must be done manually, by setting the
"Capture" property to True for the form itself.

For the sample project used in this thread, the QueryContinueDrag becomes:

====8<===CODE================================

Private Sub ListView1_QueryContinueDrag(ByVal sender As Object, ByVal e As
System.Windows.Forms.QueryContinueDragEventArgs) Handles
ListView1.QueryContinuedrag

If e.Action = DragAction.Drop Then

Me.Capture = True ' <- gains mouse control

MsgBox("First Message") 'press SPACEBAR to hide this
MsgBox("Second message") 'this can be hidden the usual way
End If

End Sub

====8<===CODE - END============================

I'd like to stress that I found this solution on my own, not on official
documentation (except for the "Capture" property reference), so I can't
assure that this is the best/officially suggested solution to this issue. It
works anyway :)

Hope this helps!

Roberto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top