如何编辑按代码添加的控件?

时间:2014-12-30 23:20:11

标签: vb.net

我的问题是什么,我让用户重命名图片框。所以我的代码是这样的:

   Dim Picturebox As New PictureBox
   Picturebox.Name = TextBox1.Text

用户可以添加另一个图片框。

如何将图片框拖动?

我知道可以通过MouseMove,MouseDown拖动图片框,但是如何?

像这样?

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As  System.Windows.Forms.MouseEventArgs) Handles "Textbox1.text".MouseDown

    End Sub

1 个答案:

答案 0 :(得分:1)

PictureBox 需要名称......

您使用AddHandler将事件连接到您的处理程序,然后转换"发件人"获取源PB的参数:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim PB As New PictureBox
    AddHandler PB.MouseMove, AddressOf PB_MouseMove
    ' ... more code with "PB" ...
End Sub

Private Sub PB_MouseMove(sender As Object, e As MouseEventArgs)
    Dim PB As PictureBox = DirectCast(sender, PictureBox)
    If e.Button = Windows.Forms.MouseButtons.Left Then
        PB.DoDragDrop("some data", DragDropEffects.All)
    End If
End Sub