以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]拖拽显示图片  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=109658)

--  作者:天一生水
--  发布时间:2017/11/16 11:46:00
--  [求助]拖拽显示图片

有点色老师的实例:拖拽文件

想实现拖拽图片并显示,但不会引用全局代码。(加黑的代码是我在全局代码中增加的,可以显示图片)

怎样在窗口中引用下面的代码:

全局代码:

Public Sub picture_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim paths As object() = e.Data.GetData(Windows.Forms.DataFormats.FileDrop)
For Each path As object In paths


 

    If Forms("窗口1").opened Then
        Dim pbx As WinForm.PictureBox = Forms("窗口1").Controls("PictureBox1")
        pbx.ImageFile = path
    End If  

  
    \'msgbox(path)
Next
sender.Cursor = System.Windows.Forms.Cursors.IBeam
End Sub

Public Sub picture_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If (e.Data.GetDataPresent(Windows.Forms.DataFormats.FileDrop)) Then
    e.Effect = Windows.Forms.DragDropEffects.Link
    sender.Cursor = System.Windows.Forms.Cursors.Arrow
Else
    e.Effect = Windows.Forms.DragDropEffects.None
End If
End Sub

 

  

 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:文件拖拽-有点色-图片.table


--  作者:有点甜
--  发布时间:2017/11/16 12:26:00
--  

 没看懂你的意思。

 

 代码必须写在全局代码里去。

 

 你具体要做什么功能?


--  作者:天一生水
--  发布时间:2017/11/16 12:37:00
--  

我在窗口的panel加入一个PictureBox控件,想拖拽图片到窗口直接显示。

这几句加黑的代码是我在全局代码中增加的,我考虑如果是多个窗口都要具备显示图片功能的话,是不是应该在各个窗口里的事件中写代码?

 


--  作者:有点甜
--  发布时间:2017/11/16 12:51:00
--  

 不可以在窗口写代码。你可以判断触发哪个窗口哪个控件,写不同的代码

 

dim fname = sender.FindForm().controls(0).name

msgbox(fname)

msgbox(sender.name)