数组求教各位高手!!!
我用以下代码画点,我想在每画一个点,就把x1,y1记录到一个数组里,当画完后,鼠标在Picture1里移动时,鼠标的x,y就和数组里的数据比较,当数据一样时,就显示x1,y1,就叫该如何写,谢谢!!!
for i=1 to 20
x1=50*i
y1=80*i
Picture1.PSet (x1, y1), vbGreen
next i
我用以下代码画点,我想在每画一个点,就把x1,y1记录到一个数组里,当画完后,鼠标在Picture1里移动时,鼠标的x,y就和数组里的数据比较,当数据一样时,就显示x1,y1,就叫该如何写,谢谢!!!
for i=1 to 20
x1=50*i
y1=80*i
Picture1.PSet (x1, y1), vbGreen
next i
只要数组到最后一个,就跳出。这样即使你怎么在窗体里移动只要与数组里的点对上就画点。
for i=1 to 20
if x=arrX(i) and y=arrY(i) then
显示XY
EXITFOR
end if
next
Dim col As New Collection
Private Sub Form_Load()
Dim i As Integer
Dim x1 As Long
Dim y1 As Long
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
For i = 1 To 20
x1 = 5 * i
y1 = 8 * i
col.Add x1 & "," & y1, "K" & x1 & ":" & y1
Picture1.PSet (x1, y1), vbRed
Next i
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo errhandle
If X = 50 And Y = 80 Then
DoEvents
End If
Me.Caption = col.Item("K" & X & ":" & Y)
Exit Sub
errhandle:
Me.Caption = ""
End Sub
Option Explicit
Dim COL(1,20)AS LONG
Private Sub Form_Load()
Dim I As Integer
Dim X As Long
Dim Y As Long
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
For I = 1 To 20
X = 50 * I
Y = 80 * I
COL(0,I)=X
COL(1,I)=Y
Picture1.PSet (X, Y), vbRed
Next
PICTURE1.REFRESH
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DIM I AS LONG
FOR I=1 TO 20
IF X=COL(0,I) AND Y=COL(1,I) THEN
ME.CAPTION="X=" & X & "Y=" & Y
EXIT FOR
ENF IF
NEXT
End Sub
这样应该满足楼主的要求了