请问大家?

jswgn201 2008-04-10 12:52:49
如果一个窗体上有40个文本框,每个文本框的内容一样,如text1.text的代码如下:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
而text2.text的代码为:
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
依次类推,如果要写完40个文本框,有没有什么办法使代码简化呀,只要写几行就可以实现以上的功能了,代码怎么写呢?
...全文
85 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
没遇到过这种情况.
回复
jswgn201 2008-04-11
谢谢大家的回答,我又学到了不少东西
回复
of123 2008-04-10
更正:

Private Sub Text1_KeyPress(Index as Integre, KeyAscii As Integer)
If (KeyAscii = 13) And (Index < Text1.Count - 1) Then
Text1(Index + 1).SetFocus
End If
End Sub
回复
of123 2008-04-10
用控件数组:
Private Sub Text1_KeyPress(Index as Integre, KeyAscii As Integer)
If (KeyAscii = 13) And (Index < Text1.Count) Then
Text1(Index + 1).SetFocus
End If
End Sub
回复
Option Explicit

'放一个text1,其index属性设置为0
Private Sub Form_Load()
Dim i As Long
For i = 1 To 20
Load Text1(i)
Next i

For i = 0 To 20
Text1(i).Left = 0
Text1(i).Top = i * 500
Text1(i).Visible = True
Next i
End Sub

Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
On Error Resume Next
Text1(Index + 1).SetFocus
End Sub
回复
做成text的数组
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-04-10 12:52
社区公告
暂无公告