【问题标题】:how to enlarge image in picturebox in vb.net如何在vb.net中放大图片框中的图像
【发布时间】:2011-05-04 18:07:00
【问题描述】:

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

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

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

  1. 拖放图片框到标签

  2. Picturebox 图像放大?

【问题讨论】:

  • 那很好。如果一个问题没有答案,它不会影响你的分数。对于有答案的问题,你最好的选择是悬赏给他们(假设你已经解锁了)。如果没有,请再次查看发布的内容并尝试他们所说的。如果没有,那很好:)

标签: c# vb.net winforms drag-and-drop


【解决方案1】:

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

您需要考虑如何处理弹出表单。

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 2022-08-22
    • 1970-01-01
    • 2013-07-14
    • 2015-12-30
    • 1970-01-01
    • 2020-01-15
    • 2010-10-19
    相关资源
    最近更新 更多