大约一个月前,Idle_Mind在开发视觉基本桌面应用程序方面得到了一些很好的帮助,孩子们可以按照正确的顺序拖放图片(图片框)。我已经展示了Idle_Mind下面提供的代码。它的作品非常漂亮,并且被学生们喜欢。在网页上拖放图片
现在,我试图在网站上重新创建应用程序。我正在使用Visual Web Developer 2008 Express。在“代码隐藏”中使用相同的代码会产生很多错误。看起来Image控件没有相同的拖放属性。
我应该试图在“后面的代码”中从Visual Basic中创建这些拖放行为,还是应该试图用html完成此操作? Visual Web Developer使用Visual Basic.net和XHTML 1.0 Transitional(我相信)
与往常一样,谢谢!
Public Class Form1
Private Source As PictureBox = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each PB As PictureBox In Me.Controls.OfType(Of PictureBox)()
PB.AllowDrop = True
AddHandler PB.MouseMove, AddressOf PBs_MouseMove
AddHandler PB.DragEnter, AddressOf PBs_DragEnter
AddHandler PB.DragDrop, AddressOf PBs_DragDrop
AddHandler PB.DragOver, AddressOf PBs_DragOver
Next
End Sub
Private Sub PBs_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim PB As PictureBox = DirectCast(sender, PictureBox)
If Not IsNothing(PB.Image) AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
Source = PB
PB.DoDragDrop(PB.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
End Sub
Private Sub PBs_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If My.Computer.Keyboard.CtrlKeyDown Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub PBs_DragOver(sender As Object, e As DragEventArgs)
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If My.Computer.Keyboard.CtrlKeyDown Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub PBs_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim PB As PictureBox = DirectCast(sender, PictureBox)
PB.Image = e.Data.GetData(DataFormats.Bitmap)
If e.Effect = DragDropEffects.Move Then
If Not (PB Is Source) Then
Source.Image = Nothing
End If
End If
End Sub
End Class
Web应用程序不是桌面应用程序,它是一个完全不同的技术堆栈。这种情况下的代码隐藏完全在服务器端运行,不能与用户界面实时交互。你会想看看在JavaScript中实现这个功能。幸运的是,诸如拖放功能等广泛使用的插件可以提供帮助。例如,看看jQuery UI插件。或interact.js,甚至只是MDN文档:https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Drag_and_drop – David
@大卫这可能是一个好的答案。 – Panzercrisis
@Panzercrisis:我不确定,因为它不是一个“回答”,因为它是进一步资源的方向。但重新阅读这个问题,我想你是对的。真的没有其他办法可以回答它。 – David