在 DragDrop VB.NET 2010 中将光标更改为反馈
正在开发 DragDrop 应用程序。我有一个类对象(作为对象构建),它有一个为 DragDrop 启用的 GroupBox。
在课堂上,我已经设置了它,以便光标在进入组框、离开组框、鼠标在组框内按下并且拖/放工作时会发生变化。我还在类对象中设置了一个标签,并更改了该标签中的文本。基本上,标签中的文本按预期发生变化,包括当我拖动对象时出现的“反馈”,但光标顽固地保持为指针。这就是当我调试该类时或在构建该类后它作为主程序的一部分运行时的情况。
这是班级中设置的替补。
Private Sub GroupBoxSourceMouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseDown
GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
lbl1.Text = "DOWN"
End Sub
Private Sub GroupBoxSourceMouseMove(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) Handles GroupBoxSource.MouseMove
If bolDragDropMouseDown Then
' Initiate dragging.
'GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
End If
bolDragDropMouseDown = False
lbl1.Text = "MOVE"
End Sub
Private Sub GroupBoxSourceMouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseEnter
Windows.Forms.Cursor.Current = Cursors.Hand
lbl1.Text = "ENTER"
End Sub
Private Sub GroupBoxSourceMouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseLeave
Windows.Forms.Cursor.Current = Cursors.Arrow
lbl1.Text = "LEAVE"
End Sub
Private Sub GroupBoxSourceDragDropFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles GroupBoxSource.GiveFeedback
Windows.Forms.Cursor.Current = Cursors.SizeAll
lbl1.Text = "FEEDBACK"
End Sub
现在进入不寻常的阶段。我决定在主程序(在表单上定义了类对象)的 FormLoad 期间将光标更改为手形,但没有任何变化。无奈之下,我设置了一个 1mS 计时器,并对其进行了编码,将光标更改为一只手,果然,光标现在是一只手,但当我移动光标时,瞬间会弹回到指针,所以看起来好像是其他东西导致了光标恢复到其默认值。
Working on a DragDrop application. I have a class object (built as an object) which has a GroupBox that is enabled for DragDrop.
In the class I have set it up so that the cursor will change when it enters the groupbox, leaves the groupbox, mouse is down within the groupbox and drag/drop is working. I also set up a label in the class object and changed the text in that label as well. Basically, the text changes in the label as expected including 'FEEDBACK' appearing when I am dragging the object BUT the cursor stays stubbornly as a pointer. This is tghe state of affairs either when I debug the class or when, after I build the class, it is run as part of the main program.
Here are the subs set up in the class.
Private Sub GroupBoxSourceMouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseDown
GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
lbl1.Text = "DOWN"
End Sub
Private Sub GroupBoxSourceMouseMove(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) Handles GroupBoxSource.MouseMove
If bolDragDropMouseDown Then
' Initiate dragging.
'GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
End If
bolDragDropMouseDown = False
lbl1.Text = "MOVE"
End Sub
Private Sub GroupBoxSourceMouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseEnter
Windows.Forms.Cursor.Current = Cursors.Hand
lbl1.Text = "ENTER"
End Sub
Private Sub GroupBoxSourceMouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseLeave
Windows.Forms.Cursor.Current = Cursors.Arrow
lbl1.Text = "LEAVE"
End Sub
Private Sub GroupBoxSourceDragDropFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles GroupBoxSource.GiveFeedback
Windows.Forms.Cursor.Current = Cursors.SizeAll
lbl1.Text = "FEEDBACK"
End Sub
Now for the unusual stage. I decided to change the cursor during FormLoad of the main program (which has the class object defined on the form) to a hand and nothing changed. In desperation I set up a 1mS timer and coded that to change the cursor to a hand and sure enough the cursor is now a hand but momentarity flicks back to a pointer when I move the cursor so it looks as if something else is causing the cursor to revert to its default value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 GiveFeedback 事件处理程序中设置 e.UseDefaultCursor = False 才能使光标更改可见。如果没有它,拖放操作将始终使用默认光标。
当鼠标悬停在控件上时获得的光标由 Control.Cursor 属性设置。更改 Cursor.Current 属性没有任何效果,该属性会导致当您移动鼠标时光标立即变回来。
You have to set e.UseDefaultCursor = False in your GiveFeedback event handler to make your cursor change visible. Without it, drag and drop always uses the default cursors.
The cursor you get when the mouse hovers a control is set by the Control.Cursor property. Changing the Cursor.Current property has no effect, the property causes the cursor to change back instantly when you move the mouse.
要轻松更改光标,请单击表单并调出属性。然后转到光标并将其更改为您想要的任何内容。
To easily change the cursor, click on the form and bring up the properties. Then go to Cursor and change it to whatever you want.