所以我是新来的和编程新手(6年前我在vb.net上做了一篇论文)。 我正在尝试编写一个工作程序,基本上我将照片从资源管理器窗口拖放到文本框中,然后显示文件路径,然后用户单击按钮并重命名文本框中的所有文件并将其放在指定的文件夹中。
我遇到的问题是有一个功能允许我添加另一个文本框,通过单击“+”按钮,并让此文本框能够将文件拖放到其中。我现在所拥有的是下面的内容。就我的研究告诉我的说,这应该有用了。
Private Sub btnAddS01_Click(sender As Object, e As EventArgs) Handles btnAddS01.Click
Dim addTB As New TextBox
Dim addLBL As New Label
lblNumberS1 = lblNumberS1 + 1
With addTB
.Name = "txtS0100" + lblNumberS1.ToString
.Location = New Point(113, TBx1)
.Size = New Size(499, 20)
.AllowDrop = True
AddHandler addTB.DragDrop, AddressOf Me.tb_DragEnter
AddHandler addTB.DragDrop, AddressOf Me.tb_DragDrop
End With
Panel0.Controls.Add(addTB)
With addLBL
.Name = "lbltxtS0100" + lblNumberS1.ToString
.Text = "00" + lblNumberS1.ToString
.Location = New Point(71, LBLx1)
.Font = New Font(addLBL.Font, FontStyle.Bold)
End With
Panel0.Controls.Add(addLBL)
End Sub
注意:lblNumberS1是一个全局变量,它允许我保留每个部分的计数并添加正确的标签号,无论用户单击“+”按钮的顺序如何。
现在进入拖放/拖动输入潜艇。 请不要为所有硬编码的文本框点燃我,我找不到更好的方法,但如果你知道一种更简单的方法,我会对它开放!
Public Sub tb_DragEnter(sender As Object, e As DragEventArgs) Handles txtH01.DragEnter, txtH02.DragEnter,
S01_001.DragEnter, S02_001.DragEnter, S03_001.DragEnter, S04_001.DragEnter, S05_001.DragEnter, S06_001.DragEnter,
S07_001.DragEnter, S08_001.DragEnter, S09_001.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Public Sub tb_DragDrop(sender As Object, e As DragEventArgs) Handles txtH01.DragDrop, txtH02.DragDrop,
S01_001.DragDrop, S02_001.DragDrop, S03_001.DragDrop, S04_001.DragDrop, S05_001.DragDrop, S06_001.DragDrop,
S07_001.DragDrop, S08_001.DragDrop, S09_001.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
sender.AppendText(path)
End If
Next
End Sub
希望一切都有道理。
任何帮助/建设性批评都将不胜感激! :)