简体   繁体   English

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

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

I want to design visual match the pairs.我想设计视觉匹配这对。 There will be two columns.将有两列。 The left column will have images and the right one will have word labels.左列将有图像,右列将有文字标签。 User have to drag image over the correct label.用户必须将图像拖到正确的 label 上。

Since the form size is small, images will have to be smaller (thumbnails).由于表单尺寸很小,因此图像必须更小(缩略图)。 So there should also be image enlargement when user hovers mouse over the image.因此,当用户将鼠标悬停在图像上时,还应该有图像放大。 The user should also still be able to do a basic drag-and-drop of the image.用户还应该能够对图像进行基本的拖放操作。

So how do I achieve both of these things?那么我如何实现这两件事呢?

  1. Drag-and-drop picturebox to label将图片框拖放到 label

  2. Picturebox image enlargement? Picturebox图像放大?

1) Drag and Drop PictureBox to Label: 1)将PictureBox拖放到Label:

First, you must set the AllowDrop property of the label to True (can also be done in designer):首先,您必须将 label 的 AllowDrop 属性设置为 True(也可以在设计器中完成):

Label.AllowDrop = True

Handle PictureBox.MouseDown to activate DragDrop:处理 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

Now, handle the DragEnter and DragDrop events of the Label:现在,处理 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)Enlarge the PictureBox on MouseOver: 2)鼠标悬停放大图片框:

Create a new Form with only a PictureBox on it.创建一个只有一个 PictureBox 的新窗体。 This is the form we will show when we want to show an enlarged image, lets call it Form2.这是我们想要显示放大图像时显示的表单,我们称之为Form2。 Now simply handle the MouseHover event of the thumbnail picture box:现在简单处理缩略图框的 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

You will need to play around with how you want to dispose of the popup form.您将需要尝试如何处理弹出表单。

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

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