创建图像热点

时间:2012-10-01 15:07:49

标签: vb.net winforms visual-studio-2010

我可能只是以错误的方式解决这个问题。我有一个PNG,它是1000x1000像素。我的形状像五角大楼,每个部分都有一个盒子。我想要做的是将每个作为PNG一部分的盒子作为可点击的盒子。我试图研究如何做到这一点,但我找不到这个问题的任何答案。提前谢谢。

2 个答案:

答案 0 :(得分:0)

您应该可以通过在单击png时检查鼠标事件参数来完成此操作。

http://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.aspx

Here是关于事件参数的教程,以及如何将它们传递给函数或子例程。

我相信this正是你要做的......

Private Sub PictureBox1_MouseDown( _
   ByVal sender As Object, _
   ByVal e As System.Windows.Forms.MouseEventArgs) _
   Handles PictureBox1.MouseDown
   Dim myPicBox As PictureBox = sender
   Select Case e.Y / myPicBox.Height
      Case Is > 2 / 3
         Debug.WriteLine("It's in the bottom third")
      Case Is > 1 / 3
         Debug.WriteLine("It's in the middle third")
      Case Else
         Debug.WriteLine("It's in the top third")
   End Select
End Sub

- 参考上一个网站。

答案 1 :(得分:0)

您可以使用这样的包含方法处理MouseMove事件和MouseDownMouseClick事件并检查Cursor是否在某个矩形内。它需要扩展以处理多个HotSpots。

Public Class Form1
    Dim hotspot1 As Rectangle = New Rectangle(25, 25, 50, 50)

    Private Sub PictureBox1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
        If hotspot1.Contains(e.X, e.Y) Then
            Beep()
        End If
    End Sub


    Private Sub PictureBox1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If hotspot1.Contains(e.X, e.Y) Then
            If Cursor <> Cursors.Hand Then Cursor = Cursors.Hand
        Else
            If Cursor <> Cursors.Default Then Cursor = Cursors.Default
        End If
    End Sub

End Class
相关问题