1) 将图片框拖放到标签上:
首先,您必须将标签的 AllowDrop 属性设置为 True(也可以在设计器中完成):
Label.AllowDrop = True
处理 PictureBox.MouseDown 以激活 DragDrop:
Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles PictureBox1.MouseDown
PictureBox1.DoDragDrop(PictureBox1, DragDropEffects.All)
End Sub
现在,处理 Label 的 DragEnter 和 DragDrop 事件:
Private Sub Label1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop
'Get the data being dropped from e.Data and do something.
End Sub
Private Sub Label1_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles Label1.DragEnter
'e.Effect controls what type of DragDrop operations are allowed on the label.
'You can also check the type of data that is being dropped on the label here
'by checking e.Data.
e.Effect = DragDropEffects.All
End Sub
2)在鼠标悬停时放大图片框:
创建一个只有一个 PictureBox 的新表单。这是我们想要显示放大图像时显示的表单,我们称之为Form2。现在简单处理缩略图框的 MouseHover 事件:
Private Sub PictureBox1_MouseHover(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
'PictureBox1 is the thumbnail on the original form.
'PictureBox2 is the full size image on the popup form.
Form2.PictureBox2.ClientSize = PictureBox1.Image.Size
Form2.PictureBox2.Image = CType(PictureBox1.Image.Clone, Image)
Form2.ShowDialog()
End Sub
您需要考虑如何处理弹出表单。