我正在开发一个针对残疾儿童的应用程序,所以我需要让它变得简单并提供大量的视觉反馈。我正在使用 Visual Basic .NET (2013),我发现的大多数示例都是针对旧版本的 VB,主要是 VB6。
无论哪种方式,我正在处理的主要功能是图像上的拖放操作。我以前从未这样做过,所以我正在开发一个测试 Windows 窗体应用程序,有两个图片框:一个是放置目标,另一个是拖动源。
问题1)到目前为止,我已经设法使源图片框在拖动操作发生时光标所在的任何地方重新定位。移动不流畅,松开鼠标后才能看到新位置的图片框。如果可能的话,我希望它给孩子用户更多关于他/她在做什么的反馈,这意味着即使在按住鼠标按钮的情况下,源图片框也会重新定位,只要图片被拖动大约。
问题 2) 当源图片框被拖动时,当我将光标拖动到不是放置目标的控件上时,我得到一个黑色的“否”光标。如何更改此光标甚至隐藏它?我尝试更改 GiveFeedback 和其他与拖放相关的事件处理程序上的光标,但在那个特定时刻似乎没有任何效果。这是一个屏幕截图来说明我在说什么:
无论哪种方式,我们的想法都是让这个应用程序感觉尽可能流畅、友好和富有表现力,或者对于可能无法阅读并因此依赖视觉和听觉反馈的 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
先感谢您!