我定义了几个textbox的数组
Text1(0),Text1(1),Text1(2),Text1(3).....
还有一个Timer控件Timer1
我本来意思是想鼠标在哪个Text1里,就动态的更改随机数.
比如,鼠标单击Text(1)上就,使得Text1(1)里面内容变
现在的情况是,我放在Text1(1)里,每个都会变.不知道有没有什么办法,可以判断鼠标点击的热点程序如下:
'鼠标按下1
Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Timer1.Enabled = True
    End If
End Sub'鼠标释放1
Private Sub Text1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Timer1.Enabled = False
    End If
End Sub'时间事件1
Private Sub Timer1_Timer()
    Dim i As Integer
    On Error Resume Next
    '第一注
    For i = 0 To 3
        Randomize
        Text1(i).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
    Next i
End Sub

解决方案 »

  1.   

    private m_Index as long Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            Timer1.Enabled = True
            m_Index = Index
        End If
    End Sub'鼠标释放1
    Private Sub Text1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            Timer1.Enabled = False
        End If
    End Sub'时间事件1
    Private Sub Timer1_Timer()
        Dim i As Integer
        On Error Resume Next
        '第一注
        Randomize
        Text1(m_Index).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
    End Sub
      

  2.   

    把timer控件去掉:
    Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
         Randomize
        Text1(Index).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
        End If
    End Sub
      

  3.   

    当鼠标按下时,记录textbox的mousedown事件中index的值,然后在时间控件里使用就可以了
      

  4.   

    这里没必要用Timer控件,既然TextBox是控件数组,直接在MouseDown事件下产生随机数就行了:
    Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            Randomize Now
            Text1(i).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
        End If
    End Sub
      

  5.   

    好好的利用index参数,
    text1(index).text=这样改变就可以了
      

  6.   

    Private Sub Text1_Click(Index As Integer)
        Randomize
        Text1(Index).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
    End Sub