0
我有一個如下所述的函數。如果用戶在面板上放置一個小圖像,我需要添加N個圖片框。 使用下面的代碼(在窗體上的拖放事件),我可以添加一個動態的圖片框。但我面臨兩個問題。如何將圖片添加到動態創建的Picturebox上,拖放事件
它只增加1個圖片框。如果我拖放一些東西,它只會替換Picturebox中的Picture。
我需要的行和列,以添加新的PictureBox的智慧,取決於面板
Public Function addPic(ByVal pic As Image, ByVal pName As String)
Dim PB As New PictureBox
With PB
.Name = pName
.SizeMode = PictureBoxSizeMode.CenterImage
.Location = New System.Drawing.Point(5, 5)
.Size = New Size(50, 50)
.BackgroundImageLayout = ImageLayout.Center
.Image = pic
' Note you can set more of the PicBox's Properties here
End With
thePanel.Controls.Add(PB)
RichTextBox1.Controls.Add(PB)
' This is the line that sometimes catches people out!
'Me.Controls.Add(PB)
PB.BringToFront()
' Wire this control up to an appropriate event handler
' AddHandler PB.Click, AddressOf MyPicClicked
AddHandler PB.MouseDown, AddressOf PictureBox_MouseHover
AddHandler PB.MouseLeave, AddressOf PictureBox_MouseLeave
' AddHandler PB.Paint, AddressOf PictureBox_Paint
Return True
End Function