<送分题>,能者多得

daizi2007 2005-11-24 05:06:39
我定义了几个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
...全文
150 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2005-11-24
  • 打赏
  • 举报
回复
Private Sub Text1_Click(Index As Integer)
Randomize
Text1(Index).Text = Format(Int(Rnd * (9 - 0 + 1)), "0")
End Sub
clear_zero 2005-11-24
  • 打赏
  • 举报
回复
好好的利用index参数,
text1(index).text=

这样改变就可以了
faysky2 2005-11-24
  • 打赏
  • 举报
回复
这里没必要用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

wangtopcool 2005-11-24
  • 打赏
  • 举报
回复
当鼠标按下时,记录textbox的mousedown事件中index的值,然后在时间控件里使用就可以了
rainstormmaster 2005-11-24
  • 打赏
  • 举报
回复
把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
weiweiplay 2005-11-24
  • 打赏
  • 举报
回复
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
daizi2007 2005-11-24
  • 打赏
  • 举报
回复
谁知道啊?

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧