繁体   English   中英

如何在 vb.net 的图片框中放大图像

[英]how to enlarge image in picturebox in vb.net

我想设计视觉匹配这对。 将有两列。 左列将有图像,右列将有文字标签。 用户必须将图像拖到正确的 label 上。

由于表单尺寸很小,因此图像必须更小(缩略图)。 因此,当用户将鼠标悬停在图像上时,还应该有图像放大。 用户还应该能够对图像进行基本的拖放操作。

那么我如何实现这两件事呢?

  1. 将图片框拖放到 label

  2. Picturebox图像放大?

1)将PictureBox拖放到Label:

首先,您必须将 label 的 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

您将需要尝试如何处理弹出表单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM