VB.NET(2013)拖放反馈

时间:2014-02-27 21:12:51

标签: vb.net user-interface drag-and-drop cursor user-friendly

我正在开发针对残疾儿童的应用程序,因此我需要简化并提供大量视觉反馈。我使用的是Visual Basic .NET(2013),我发现的大部分示例都是针对VB的旧版本,主要是VB6。

无论哪种方式,我正在处理的主要功能是对图像进行拖放操作。我之前从未这样做过,所以我正在开发一个测试Windows窗体应用程序,有两个图片框:一个是放置目标,另一个是拖动源。

问题1)到目前为止,我已经设法让源图片框在拖动操作发生时光标所在的位置重新定位。移动不平滑,只有松开鼠标按钮才能看到新位置的图片框。如果可能的话,我希望能给孩子用户更多关于他/她正在做什么的反馈,这意味着即使在按住鼠标按钮的同时使源图片框重新定位,只要图片被拖动周围。

问题2)当拖动源图片框时,当我将光标拖到不是放置目标的控件上时,我得到一个黑色的“No”光标。如何更改此光标甚至隐藏它?我已经尝试更改GiveFeedback和其他拖放相关事件处理程序上的光标,但似乎没有任何东西适用于该特定时刻。这是一个截图来说明我的意思:

Issue 2 Illustration

无论哪种方式,我们的想法是让这个应用程序感觉尽可能顺利,友好和富有表现力的PDD儿童(例如自闭症),他们可能无法阅读,因此依赖于视觉和听觉反馈。将在表单周围拖动图片以创建句子(如果您想了解更多信息,请查看PECS)。

到目前为止,这是我的拖放代码(请原谅我们):

Public Class frmDragDropExample
Private mouseIsDown As Boolean = False ' Use this variable as a flag to indicate when the mouse is down
Private Offset As Point 'Use this to set the offset position, to move the picture being dragged

Private Sub frmDragDropExample_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' Declare this picture box as the target of the drag-and-drop operation
    dragDropTargetPictureBox.AllowDrop = True
End Sub

Private Sub dragDropSourcePictureBox_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles dragDropSourcePictureBox.GiveFeedback
    ' Nothing here yet!
End Sub

Private Sub sourcePictureBox_MouseDown(sender As Object, e As MouseEventArgs) Handles dragDropSourcePictureBox.MouseDown
    ' Indicate that the mouse is down
    mouseIsDown = True
    Cursor.Current = Cursors.Hand
    ' Set the offset values to move the picture being dragged
    Offset.X = MousePosition.X - sender.Left
    Offset.Y = MousePosition.Y - sender.Top
End Sub


Private Sub sourcePictureBox_MouseMove(sender As Object, e As MouseEventArgs) Handles dragDropSourcePictureBox.MouseMove
    If mouseIsDown Then
        ' Initiate the dragging.
        dragDropSourcePictureBox.DoDragDrop(dragDropSourcePictureBox.Image, DragDropEffects.Move)
        ' Move the object along with the cursor for more feedback (the user should tell that the object is being moved around)
        sender.Left = MousePosition.X - Offset.X
        sender.Top = MousePosition.Y - Offset.Y
    End If
    ' Otherwise... mouse is down.
    mouseIsDown = False
End Sub

Private Sub targetPictureBox_DragDrop(sender As Object, e As DragEventArgs) Handles dragDropTargetPictureBox.DragDrop
    ' Paste the picture.
    dragDropTargetPictureBox.Image = e.Data.GetData(DataFormats.Bitmap)
    ' Play a sound as feedback (the picture has been moved!).
    My.Computer.Audio.Play(My.Resources.sfx_paper_flip_01, AudioPlayMode.Background)
    ' Also color the target pictue box white again, as feedback
    dragDropTargetPictureBox.BackColor = Color.White
    ' Dispose of the picture (should handle garbage collection, too --so many pictures!)
    dragDropSourcePictureBox.Dispose()
End Sub


Private Sub targetPictureBox_DragEnter(sender As Object, e As DragEventArgs) Handles dragDropTargetPictureBox.DragEnter
    ' Check the format of the data being dropped --it should be a bitmap/image
    If (e.Data.GetDataPresent(DataFormats.Bitmap)) Then
        ' Color the target picture box for feedback
        dragDropTargetPictureBox.BackColor = Color.LightGray
        ' Display the move cursor.
        e.Effect = DragDropEffects.Move
    Else
        ' Display the no-drop cursor.
        e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub dragDropTargetPictureBox_DragLeave(sender As Object, e As EventArgs) H

andles dragDropTargetPictureBox.DragLeave
        dragDropTargetPictureBox.BackColor = Color.White
    End Sub
End Class

提前谢谢!

0 个答案:

没有答案