请问自动拖放功能如何实现?
假设有程序A支持拖放功能,例如支持手动拖放文件添加到程序A的文件列表里。程序B可以自动将文件拖放到程序A中,请问程序B的功能如何实现?
[解决办法]
说明白点啊,不是很清楚需要什么
[解决办法]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.AllowDrop = True
End Sub
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
PictureBox1.Image = Image.FromFile(files(0))
End If
End Sub
[解决办法]
跨程序拖放文件。也可以啊。
拖放的是文件应该可以的。
写好程序A的“拖”事件、并传文件路径,在程序B的接受控件写好“放”事件。
[解决办法]
不知道模拟移动文件到目标程序中是否可以实现
[解决办法]
notepad
notepad "D:\My Documents\REMARK.txt"
[解决办法]
看你提的:9楼,我去测试一下。
[解决办法]
在自己的程序A中处理一下“拖出”数据格式为:DataFormats.FileDrop就可以了。只是要注意托的文件格式是否是你程序B支持的文件格式。
参考:http://www.cnblogs.com/eaglet/archive/2009/01/06/1370149.html
---------
本人自己的测试代码:
- VB.NET code
Private Sub ListBoxFileList_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBoxFileList.MouseMove'在ListBox中加入图片文件的路径。鼠标拖放里面的项,拖放到PhotoShop里面,可以打开那个图片文件。'加入Txt文本文件,拖放到支持文本文件格式的另外一个程序,也可以打开。 If e.Button = Windows.Forms.MouseButtons.Left Then If Me.ListBoxFileList.SelectedItem IsNot Nothing Then Dim data As DataObject = New DataObject(DataFormats.FileDrop, Me.ListBoxFileList.SelectedItems(0).ToString) '//data.SetData(DataFormats.StringFormat, files) '//Do DragDrop Dim sc As New System.Collections.Specialized.StringCollection sc.Add(Me.ListBoxFileList.SelectedItems(0).ToString) 'MsgBox(sc.Item(0).ToString) data.SetFileDropList(sc) DoDragDrop(data, DragDropEffects.All) End If End If End Sub
[解决办法]
Mark
[解决办法]
这个问题你这么想就太远了,没法解决了,你换一种思路就很简单了,
做一个程序,打开一个文件夹,遍历目录内的全部JPG文件,执行
- VB.NET code
shell (a.exe b.jpg)