关于TextBox的一个有意思的现象:(关键字:TextBox,MultiLine,KeyCode)

xo2000 2003-05-07 03:55:03
关于TextBox的一个有意思的现象:
把Text1,Text2,Text3的MultiLine置为true后,按下键盘的上下键,能响应用于测试的MsgBox,但却不能转移焦点,但是对于左右键却可以,不知为什么。请高手指点一下!
代码如下:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text2.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text2.SetFocus
End Select
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text1.SetFocus
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text1.SetFocus

Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text3.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text3.SetFocus
End Select
End Sub

Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text2.SetFocus
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text2.SetFocus
End Select
End Sub
...全文
27 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xo2000 2003-05-09
已经结贴了,怎么看不到给分情况呢?
各位,收到分了吧!
回复
DaiLM 2003-05-08
vbkeycancel表示按键取消,也就是表示不按键
你可以根据自己的要求改变其位置以达到目的
回复
DaiLM 2003-05-08
比如:

Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text2.SetFocus
keycode=vbkeycancel
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text1.SetFocus
keycode=vbkeycancel
Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text1.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text2.SetFocus
End Select
End Sub

这时按左和下后就不会对下一控件产生作用了,但是右和上有可能还会对下一控件产生作用
回复
xo2000 2003-05-08
楼上能否详细解释一下什么时候要用这句代码。
或者说为什么左右键不用没问题,而上下键就必须用呢?
回复
kmzs 2003-05-07
上下键要在行间转换……
回复
xo2000 2003-05-07
谢谢各位,用 DaiLM()的方法把问题解决了!

DaiLM() 能否解释一下为什么要用
KeyCode = vbKeyCancel
,为什么左右键不用没问题,而上下键就必须用呢?谢谢!
回复
DaiLM 2003-05-07
已改过,并通过了!

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text3.SetFocus
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text2.SetFocus
Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text2.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text3.SetFocus
End Select
KeyCode = vbKeyCancel
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text1.SetFocus
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text3.SetFocus
Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text3.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text1.SetFocus
End Select
KeyCode = vbKeyCancel
End Sub

Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft:
MsgBox "KeyLeft Pressed"
Text2.SetFocus
Case vbKeyDown:
MsgBox "KeyDown Pressed"
Text1.SetFocus
Case vbKeyRight:
MsgBox "KeyRight Pressed"
Text1.SetFocus
Case vbKeyUp:
MsgBox "KeyUp Pressed"
Text2.SetFocus
End Select
KeyCode = vbKeyCancel
End Sub
回复
xo2000 2003-05-07
to victorycyz(中海) :试了,也不管用。应该没什么关系,不然,左右键怎么行呢?
to Leftie(Leftie) :也不行,更本执行不到Case vbKeyReturn这一句,我设断点试了。
回复
饮水需思源 2003-05-07
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
text3.setfocus
Case vbKeyDown
Text3.SetFocus
MsgBox "KeyRight Pressed"

Case vbKeyUp
Text1.SetFocus
MsgBox "KeyUp Pressed"

End Select
End Sub
回复
victorycyz 2003-05-07
先把text3_keydown()注释掉看看。
回复
xo2000 2003-05-07
to victorycyz(中海) :结果一样,不起作用。
另外似乎有一个现象:比如丛text2按up,光标好象闪到tex3后又闪回来了。(有时出现这个现象,希望不是我看看花眼了:))
回复
victorycyz 2003-05-07
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight:
Text2.SetFocus
MsgBox "KeyRight Pressed"

Case vbKeyUp:
Text2.SetFocus
MsgBox "KeyUp Pressed"

End Select
End Sub
这样呢?
回复
相关推荐
基于java的企业人事管理系统设计--软件工程课程设计(含源码与论文设计).rar 1 引言 4 1.1 课程设计目标 4 1.2 编程工具(编程环境)介绍 4 1.3 实施时间及主要实施步骤 4 2 需求分析 5 3 系统总体设计 6 4 数据库设计 6 5 主要功能模块的设计与实现 10 5.1 功能模块1详细设计(综合查询员工信息)..........................................................10 5.1.1 详细设计.......................................................................................................10 5.1.2 算法流程........................................................................................................15 5.1.3 界面设计及测试结果.....................................................................................15 6 调试分析 15 7 用户手册 16 8 测试结果 17 8.1 员工信息的添加...................................................................................................17 8.2 员工信息的修改...................................................................................................17 8.3 员工信息的删除...................................................................................................18 8.4 员工信息的综合查询...........................................................................................18 8.5 员工信息按性别统计的结果................................................................................19 8.6 员工信息按状态统计的结果...............................................................................19 8.7 员工信息按职称统计的结果................................................................................20 9 结论 20 10 参考文献 20
发帖
VB基础类
创建于2007-09-28

7493

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-07 03:55
社区公告
暂无公告