如何将一组动态创建的文本框拖放? [英] How can I make an array of dynamically created text boxes drag and drop?

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

问题描述

我可以创建一个文本框数组,但添加tb.dodragdrop不会使它们拖放。创建它们时需要添加什么?



这是目前为止的部分代码列表,不允许从图像文件中删除图像名称: br />

I can create an array of text boxes but adding tb.dodragdrop does not make them drag and drop. what do I need to add when they are created?

This is a partial list of code so far which doesn't allow dropping image names from the image files:

Dim TextCtrl(13) As TextBox
Dim xLoc1 As Integer = 10
Dim yLoc1 As Integer = 30
'-----Add textboxes as arrays
For count1 As Integer = 0 To 13
    Dim tb As New TextBox
    tb.Location = New Point(xLoc1, yLoc1)
    tb.Name = "TextCtrl"
    tb.DoDragDrop()
    Me.Controls.Add(tb)
    TextCtrl(count1) = tb '<-- This line adds the TextBox to the array.
    TextCtrl(count1).AllowDrop = True
    TextCtrl(count1).DoDragDrop(e, DragDropEffects.All)

    yLoc1 += 25
Next count1

推荐答案

您需要在TextBox中添加处理程序来处理关键的DragAndDrop事件:DragEnter和DragDrop:这显示了如何添加处理程序: HTTP:/? /msdn.microsoft.com/en-us/library/ms743596(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 [<一个HREF = http://msdn.microsoft.com/en-us/library/ms743596(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 target =_ blanktitle =New Window> ^ ]

DragEnter处理程序需要检查数据源是否兼容,并正确设置Effect属性和DragDrop处理程序需要采取行动。

这也可能有所帮助: http:// msdn.microsoft.com/en-us/library/aa289508(v=vs.71).aspx [ ^ ]



如果没有正确实施两个处理程序,什么都不会发生。
You need to add handlers to your TextBox to handle the critical DragAndDrop events: DragEnter and DragDrop: this shows how to add handlers: http://msdn.microsoft.com/en-us/library/ms743596(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]
The DragEnter handler needs to check if the data source is compatible, and set the Effect property appropriately, and the DragDrop handler needs to action the drop.
This may also help: http://msdn.microsoft.com/en-us/library/aa289508(v=vs.71).aspx[^]

Without the two handlers correctly implemented, nothing will happen.


这篇关于如何将一组动态创建的文本框拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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