加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB实现简单的图形区域选择

发布时间:2020-12-16 23:10:07 所属栏目:大数据 来源:网络整理
导读:程序效果: 当点击左边的部件图时,会弹出对话框提示你点击了哪一个区域。 程序思路: 用一个图片区域码图作为点击区域的参照,根据XY取得的颜色识别出属于哪一个区域 程序界面如下: 相关代码如下: Visual Basic Code Dim ColorArray ( ) As Long Dim Colo

程序效果:

当点击左边的部件图时,会弹出对话框提示你点击了哪一个区域。

程序思路:

用一个图片区域码图作为点击区域的参照,根据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

本程序的源代码可以到以下地址下载:

http://download.csdn.net/source/2294631

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读