我可能只是走错了路,我不知道。我有一个PNG,它是1000x1000像素的。我的形状像一个五边形,在每个部分我都有一个盒子。我想要做的是让每个框是PNG的一部分,成为一个可点击的框。我试图研究如何做到这一点,但我找不到这个问题的任何答案。提前谢谢你。
发布于 2012-10-01 23:18:39
您应该能够通过在单击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最后一个网站的-Reference。
发布于 2012-10-01 23:32:54
您可以处理MouseMove事件和MouseDown或MouseClick事件,并检查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 Classhttps://stackoverflow.com/questions/12675944
复制相似问题