PictureBox控件没有AllowDrop,如何解决拖放问题

清风不拂面 2020-07-22 06:14:35
我现在用的是vs2017+win10 ,PictureBox控件没有AllowDrop属性,如何解决拖放图片文件到图片框的问题?谢谢
另外,尝试在窗体控件设置AllowDrop=true后,拖放文件也不成功,是怎么回事?
...全文
1884 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
5idonet 2020-07-23
  • 打赏
  • 举报
回复
‘可以考虑将PictureBox放在Panel中
'Me.Panel1.AllowDrop = True
Private Sub Panel1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Panel1.DragDrop
Dim str() As String = CType(e.Data.GetData(DataFormats.FileDrop, False), String())
If str.Length > 1 Then
Exit Sub
Else
sender.Text = str(0)
Me.PictureBox1.ImageLocation = str(0)
End If
End Sub

Private Sub Panel1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Panel1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
  • 打赏
  • 举报
回复
我也发现 richtextbox 也没有 allowdrop 这个属性!
清风不拂面 2020-07-23
  • 打赏
  • 举报
回复
非常好,问题解决,谢谢!

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧