程序效果:
当点击左边的部件图时,会弹出对话框提示你点击了哪一个区域。
程序思路:
用一个图片区域码图作为点击区域的参照,根据XY取得的颜色识别出属于哪一个区域
程序界面如下:
相关代码如下:
Visual Basic Code |
Dim ColorArray ( ) As Long Dim ColorCount As Long Private Sub Form_Load ( ) '初始化颜色数量 ColorCount = Picture3.Width / 10 ReDim ColorArray ( 1 To ColorCount ) For X = 1 To ColorCount ColorArray ( X ) = Picture3.Point ( ( X * 10 ) - 5, 5 ) Next X End Sub Private Sub Picture1_MouseDown ( Button As Integer,Shift As Integer,X As Single,Y As Single ) If Button = 1 Then Dim NowColor As Long NowColor = Picture2.Point ( X,Y ) If NowColor <> RGB ( 255, 255, 255 ) Then Dim i As Long For i = 1 To ColorCount If NowColor = ColorArray ( i ) Then ButtonClick i Exit For End If Next i End If End If End Sub Private Sub ButtonClick ( Index As Long ) MsgBox "你点击了第 " & Index & "个按钮",64, "提示" End Sub |
本程序的源代码可以到以下地址下载: