拖放 [英] Drag-Drop

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

问题描述

我第一次使用DoDragDrop方法工作。我已经差不多了,但是我需要一些帮助。


我的表单上有两个列表框,lstGroups和lstStudents。我希望能够从lstStudents中拖出一个名字并将其放在

lstGroups中的一个名称上,以将其移动到该组。我有拖曳的部分工作;

它只是还没有下降。我正在使用msdn库和我找到的另一个示例项目找到我能找到的
。我正在尝试

将代码中的代码转换为我项目所需的代码。

这是我到目前为止的lstGroups.DragDrop子: br />

Private Sub lstGroups_DragDrop(ByVal sender As Object,ByVal e As

System.Windows.Forms.DragEventArgs)处理lstGroups.DragDrop

Dim Pt As Point = lstGroups.PointToClient(New Point(eX,eY))

Dim DestinationFolder As String = lstGroups.GetItemText(Pt)

End Sub


我希望DestinationFolder被分配组名的文本(在

lstGroups中),其中学生的名字被删除。上面的代码给了我

Pt的x / y坐标。我从哪里开始?


非常感谢,

Nathan

I''m working for the first time with the DoDragDrop method. I''ve got almost
everything worked out, but I need some help with the last bit.

There are two listboxes on my form, lstGroups and lstStudents. I want to be
able to drag a name from lstStudents and drop it on one of the names in
lstGroups to move it to that group. I''ve got the dragging part working;
it''s just the dropping that isn''t there yet. I''m working with what I can
find from the msdn library and another sample project I found. I''m trying
to convert the code from the samples to the code I need for my project.
This is the lstGroups.DragDrop sub I have so far:

Private Sub lstGroups_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstGroups.DragDrop
Dim Pt As Point = lstGroups.PointToClient(New Point(e.X, e.Y))
Dim DestinationFolder As String = lstGroups.GetItemText(Pt)
End Sub

I want DestinationFolder to be assigned the text of the group name (in
lstGroups) where the student''s name is dropped. The code above is giving me
the x/y coordinates of Pt. Where do I go from here?

Thanks a lot,
Nathan

推荐答案

你知道吗,如果不是你的MVP(以及其他人在这个NG上好吧)我会在很久以前卸载VS并放弃它。 br />
感谢您的帮助。


我现在还有另外一个问题。

启动拖放的lstStudents.MouseDown事件似乎已经覆盖了

lstStudents.SelectedIndexChanged和lstStudents.DoubleClick事件。这些

事件不起作用,除非我评论拖拽潜艇。知道什么是'b $ b'错了吗?

You know, if it weren''t for you MVPs (and the other folks on this NG as
well) I would have uninstalled VS and given up on this a long time ago.
Thanks for the help.

There is one other problem I have now. The lstStudents.MouseDown event that
starts the drag-drop seem to have "overridden" the
lstStudents.SelectedIndexChanged and lstStudents.DoubleClick events. These
events don''t work unless I comment out the drag-drop subs. Any idea what''s
wrong?


文章< e7 ********** ****@TK2MSFTNGP10.phx.gbl>,
nk ********************* @softhome.net 说...
In article <e7**************@TK2MSFTNGP10.phx.gbl>,
nk*********************@softhome.net says...
你知道,如果不是'这对你来说是MVP(以及这个NG上的其他人好吧)我很久以前就已经卸载了VS并放弃了这个。
感谢您的帮助。


感谢您的注意! :)

我现在还有另外一个问题。
启动拖放的lstStudents.MouseDown事件似乎具有覆盖功能。
lstStudents.SelectedIndexChanged和lstStudents.DoubleClick事件。除非我评论拖拽潜艇,否则这些事件不会奏效。知道什么是错的吗?
You know, if it weren''t for you MVPs (and the other folks on this NG as
well) I would have uninstalled VS and given up on this a long time ago.
Thanks for the help.
Thanks for noticing! :)
There is one other problem I have now. The lstStudents.MouseDown event that
starts the drag-drop seem to have "overridden" the
lstStudents.SelectedIndexChanged and lstStudents.DoubleClick events. These
events don''t work unless I comment out the drag-drop subs. Any idea what''s
wrong?




我环顾谷歌,发现这篇帖子使用了

SystemInformation.DragSize来确定mousedown / mousemove

是否应该开始拖放或只是作为mousedown和

mousemove处理。它可能对你有帮助。

http://tinyurl.com/3eyuw

Patrick Steele

Microsoft .NET MVP
http://weblogs.asp.net/psteele


感谢您的链接。我没有其他任何语言的经验,但是

我尽我所能解释那里的代码以适应我所拥有的。

我有它(代码发布在下面),我可以选择一个学生的名字,但

没有拖拽工作。也许你可以弄清楚出了什么问题?


\\

Dim DragRectangle as Rectangle = Rectangle.Empty

Dim Index as Integer


Private Sub lstStudents_MouseDown(ByVal sender As Object,ByVal e As

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

lstStudents.SelectedIndex = lstStudents.IndexFromPoint(eX,eY)


如果lstStudents.SelectedIndex = -1那么''???这是从链接中的代码正确的

解释吗?如果是这样,我不明白为什么

Dim RecSize As Size = SystemInformation.DragSize

DragRectangle =新矩形(新点(eX - CInt(RecSize.Width /)

2),eY - CInt(RecSize.Height / 2)),RecSize)

Else

DragRectangle = Rectangle.Empty

结束如果


End Sub


Private Sub lstStudents_MouseUp(ByVal sender As Object,ByVal e As

System.Windows.Forms.MouseEventArgs)处理lstStudents.MouseUp

DragRectangle = Rectangle.Empty

结束子


Private Sub lstStudents_MouseMove(ByVal sender As Object,ByVal e As

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

如果DragRectangle.IsEmpty和DragRectangle.Contains(eX ,等等)然后

lstStudents.DoDragDrop(lstStudents.Items(Index),

DragDropEffects.Move)

结束如果

End Sub


Private Sub lstStudents_SelectedIndexChanged(ByVal se nder As Object,ByVal e

As System.EventArgs)处理lstStudents.SelectedIndexChanged

EnableButtons()''启用或禁用某些按钮

根据学生的姓名是否被选中

结束子


\\
Thanks for the link. I don''t have any experience with other languages, but
I did the best I could at interpreting the code there to fit what I have.
As I have it (code is posted below), I can select a student''s name, but
nothing with the drag-drop works. Maybe you can figure out what''s wrong?

\\
Dim DragRectangle as Rectangle = Rectangle.Empty
Dim Index as Integer

Private Sub lstStudents_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstStudents.MouseDown
lstStudents.SelectedIndex = lstStudents.IndexFromPoint(e.X, e.Y)

If lstStudents.SelectedIndex = -1 Then '' ??? Is this the correct
interpretation from the code in the link? If so, I don''t understand why
Dim RecSize As Size = SystemInformation.DragSize
DragRectangle = New Rectangle(New Point(e.X - CInt(RecSize.Width /
2), e.Y - CInt(RecSize.Height / 2)), RecSize)
Else
DragRectangle = Rectangle.Empty
End If

End Sub

Private Sub lstStudents_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstStudents.MouseUp
DragRectangle = Rectangle.Empty
End Sub

Private Sub lstStudents_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstStudents.MouseMove
If DragRectangle.IsEmpty And DragRectangle.Contains(e.X, e.Y) Then
lstStudents.DoDragDrop(lstStudents.Items(Index),
DragDropEffects.Move)
End If
End Sub

Private Sub lstStudents_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles lstStudents.SelectedIndexChanged
EnableButtons() ''This enables or disenables certain buttons
according to whether a student''s name is selected
End Sub

\\


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

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