DragDrop问题 [英] DragDrop Question

查看:87
本文介绍了DragDrop问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的问题是关于DragDrop,


我如何实现从列表视图拖放和Drop on Desktop或任何其他

计算机上的文件夹。


listview包含文件列表,所以基本上我应该可以放弃

那些我计算机上其他文件夹上的文件。


我希望在.net 2.0中有可能


谢谢


Ratnesh

解决方案

bump


如果有人知道答案


" Ratnesh Raval" < ra ********** @ gmail.comwrote in message

news:eF ************** @ TK2MSFTNGP04.phx.gbl ...


大家好,


我的问题在于DragDrop,


我如何实现从listview和Drop on Desktop或任何

计算机上的其他文件夹中的拖动。


listview包含文件列表,所以基本上我应该能够将这些文件放在我电脑上的其他文件夹上。


我希望在.net 2.0中有可能


谢谢


Ratnesh





" Ratnesh Raval" < ra ********** @ gmail.comwrote in message

news:%2 **************** @ TK2MSFTNGP06。 phx.gbl ...


bump


如果有人知道答案


" Ratnesh Raval" < ra ********** @ gmail.comwrote in message

news:eF ************** @ TK2MSFTNGP04.phx.gbl ...


>大家好,

我的问题在于DragDrop,

我将如何实施从列表视图和桌面上的Drop或计算机上的任何其他文件夹中拖动。

listview包含文件列表,所以基本上我应该能够删除这些文件我计算机中的其他文件夹。

我希望在.net 2.0中有可能

谢谢

Ratnesh




Ratnesh,


我现在在工作,所以我无法访问我的家用电脑。我有一个

样本的拖放文件。这很简单,但是当我回到家的时候,我会发一个

的代码。


LS




" Lloyd Sheen" < a@b.cwrote in message

news:8A ****************************** **** @ microsof t.com ...


>

" Ratnesh Raval" < ra ********** @ gmail.comwrote in message

news:%2 **************** @ TK2MSFTNGP06。 phx.gbl ...


> bump

如果有人知道答案

Ratnesh Raval ; < ra ********** @ gmail.comwrote in message
新闻:eF ************** @ TK2MSFTNGP04.phx.gbl ...


>>大家好,

我的问题在于DragDrop,

我将如何实现Drag从listview和Drop on Desktop或计算机上的任何其他文件夹。

listview包含文件列表,所以基本上我应该能够将这些文件放在其他文件夹上在我的电脑里。

我希望在.net 2.0中有可能

谢谢

Ratnesh




Ratnesh,


我现在在上班,所以我无法进入我的家PC。我有一个

样本的拖放文件。这很简单,但是当我回到家的时候,我会发一个

的代码。


LS



Ratnesh,


以下是一些示例代码:


以下是用于鼠标D& D处理的变量移动。


私有_MouseDown为布尔值=错误

私有_MouseX为整数

私有_MouseY为整数

Private _MouseButtons As MouseButtons

Private _SwitchContext As Boolean = False


当我的列表浏览器上按下鼠标按钮时会发生以下情况


Private Sub List_MouseDown(ByVal sender As System.Object,ByVal e As

System.Windows.Forms.MouseEventArgs)处理SongFileView.MouseDown

_MouseButtons = e.Button

_SwitchContext = False

_MouseDown = True

_MouseX = eX

_MouseY = eY
结束子


以下是在移动mou时发生的情况SE。我使用了一个测试距离

鼠标移动以防止误拖放操作:


Private Sub List_MouseMove(ByVal sender As System.Object,ByVal e As

System.Windows.Forms.MouseEventArgs)处理SongFileView.MouseMove

Dim lv作为ListView = DirectCast(发件人,ListView)

Dim sc作为新的StringCollection


如果_MouseDown那么

如果Math.Abs​​(_MouseX - eX)< 5或Math.Abs​​(_MouseY - e.Y)< 5

然后

退出Sub

结束如果

Dim xx As DataObject = New DataObject

Dim yy As ArrayList = New ArrayList

For each idx As Integer in lv.SelectedIndices

Dim li As ListViewItem = lv.Items(idx)

yy.Add(li.SubItems(5).Text +" \" + li.Text)

sc.Add(li.SubItems(5).Text +" ; \" + li.Text)

下一页


Dim zz As Array = yy.ToArray

xx.SetFileDropList (sc)

xx.SetData(" ListItems",lv.SelectedItems)

尝试

lv.DoDragDrop(xx,DragDropEffects.Copy )

_MouseDown = False

Catch ex As Exception

Dim zzzz As Integer = 1

结束尝试


结束如果

结束次级


如果鼠标按钮释放,则以下将重置D& D

listview:


Private Sub SongFileView_MouseUp(ByVal sender As System.Object,ByVal e

As System.Windows.Forms.MouseEventArgs)处理SongFileView.MouseUp

_MouseDown = False

结束子

希望这会有所帮助:


Lloyd Sheen


Hi All,

My question is on DragDrop,

How would I implement a Drag from listview and Drop on Desktop or any other
folder on the computer.

The listview contains list of files, so basically I should be able to drop
those files on other folders in my computer.

I hope that''s possible in .net 2.0

Thanks

Ratnesh

解决方案

bump

if anybody knows the answer

"Ratnesh Raval" <ra**********@gmail.comwrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...

Hi All,

My question is on DragDrop,

How would I implement a Drag from listview and Drop on Desktop or any
other folder on the computer.

The listview contains list of files, so basically I should be able to drop
those files on other folders in my computer.

I hope that''s possible in .net 2.0

Thanks

Ratnesh




"Ratnesh Raval" <ra**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

bump

if anybody knows the answer

"Ratnesh Raval" <ra**********@gmail.comwrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...

>Hi All,

My question is on DragDrop,

How would I implement a Drag from listview and Drop on Desktop or any
other folder on the computer.

The listview contains list of files, so basically I should be able to
drop those files on other folders in my computer.

I hope that''s possible in .net 2.0

Thanks

Ratnesh


Ratnesh,

I am at work right now so I don''t have access to my home PC. I do have a
sample of drag and drop of files. It is quite simple but I will post a
little of the code when I get home.

LS



"Lloyd Sheen" <a@b.cwrote in message
news:8A**********************************@microsof t.com...

>
"Ratnesh Raval" <ra**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

>bump

if anybody knows the answer

"Ratnesh Raval" <ra**********@gmail.comwrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...

>>Hi All,

My question is on DragDrop,

How would I implement a Drag from listview and Drop on Desktop or any
other folder on the computer.

The listview contains list of files, so basically I should be able to
drop those files on other folders in my computer.

I hope that''s possible in .net 2.0

Thanks

Ratnesh



Ratnesh,

I am at work right now so I don''t have access to my home PC. I do have a
sample of drag and drop of files. It is quite simple but I will post a
little of the code when I get home.

LS

Ratnesh,

Here is some sample code:

The following are variables used for the D&D processsing of mouse moves.

Private _MouseDown As Boolean = False
Private _MouseX As Integer
Private _MouseY As Integer
Private _MouseButtons As MouseButtons
Private _SwitchContext As Boolean = False

The following happens when the mouse button is pressed over my listview

Private Sub List_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseDown
_MouseButtons = e.Button
_SwitchContext = False
_MouseDown = True
_MouseX = e.X
_MouseY = e.Y
End Sub

The following happens on a move of the mouse. I use a test for the distance
the mouse has moved to prevent false drag drop operations:

Private Sub List_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseMove
Dim lv As ListView = DirectCast(sender, ListView)
Dim sc As New StringCollection

If _MouseDown Then
If Math.Abs(_MouseX - e.X) < 5 Or Math.Abs(_MouseY - e.Y) < 5
Then
Exit Sub
End If
Dim xx As DataObject = New DataObject
Dim yy As ArrayList = New ArrayList
For Each idx As Integer In lv.SelectedIndices
Dim li As ListViewItem = lv.Items(idx)
yy.Add(li.SubItems(5).Text + "\" + li.Text)
sc.Add(li.SubItems(5).Text + "\" + li.Text)
Next

Dim zz As Array = yy.ToArray
xx.SetFileDropList(sc)
xx.SetData("ListItems", lv.SelectedItems)
Try
lv.DoDragDrop(xx, DragDropEffects.Copy)
_MouseDown = False
Catch ex As Exception
Dim zzzz As Integer = 1
End Try

End If
End Sub

The following will reset the D&D if the mouse button is release over the
listview:

Private Sub SongFileView_MouseUp(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseUp
_MouseDown = False
End Sub
Hope this helps:

Lloyd Sheen


这篇关于DragDrop问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆