在VB6中该如何将TAB键的功能应用在ENTER键上

zhuangzai 2003-03-12 05:47:28
请各位指教!
谢谢!
...全文
152 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xks 2003-03-16
  • 打赏
  • 举报
回复
上面的是函数定义!

在模块中输入上面的代码!
xks 2003-03-16
  • 打赏
  • 举报
回复
Public Sub EnterToTab(Keyasc As Integer)
If Keyasc = 13 Then
SendKeys "{TAB}"
End If
End Sub

这是我的程序中的一段代码!

好用的!

不过得在程序中做调用!

我想你会做吧!
scsun 2003-03-16
  • 打赏
  • 举报
回复
把Form的KeyPress设为true.

然后在所有需要把TAB换成Enter的控件事件

Private Sub Text_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
SendKeys "{TAB}"
KeyAscii=0
End If

End Sub

用户 昵称 2003-03-14
  • 打赏
  • 举报
回复
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim M As msg

If KeyCode = vbKeyEscape Then
Unload Me
ElseIf KeyCode = vbKeyReturn Then
PeekMessage M, Me.hWnd, 0, 0, PM_REMOVE
End If
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHAndler

If KeyCode = vbKeyReturn Or KeyCode = vbKeyDown Then
Text1(Index + 1).setfocus
ElseIf KeyCode = vbKeyUp Then
Text1(Index - 1).setfocus
End If
Exit Sub
ErrHAndler:
'┏━━━━━━━━━┓
'┃容错处理,把焦点设置在确定按钮上或者text1(0)上
'┗━━━━━━━━━┛
If OKButton.Enabled Then
OKButton.SetFocus '最上一个文本框中向上
Else
Text1(0).setfocus '最下一个文本框中向下或者输入数据非法
End If
Err = 0
End Sub

Private Sub Text1_ChAnge(Index As Integer) '检查是否都是数字
Dim I As Integer

For I = 0 To 6
If Not IsNumeric(Text1(I).Text) Then
OKButton.Enabled = False
Exit Sub
End If
Next I
OKButton.Enabled = True
End Sub

...
用户 昵称 2003-03-14
  • 打赏
  • 举报
回复
我还是坚持我的意见,我很早以前解决这个问题的时候发现sendkeys多次的时候会引起系统瘫痪,很多极其都这样,我的方法

1)form.preview = true
2)把相同的控件做成数组
3)在form的onkeydown中调用peekmessage删除回车事件。
4)在控件的onkeydown中下一控件setfocus
5)还可以解决上下左右等等。
lightice 2003-03-14
  • 打赏
  • 举报
回复
我顶
hjwsir 2003-03-14
  • 打赏
  • 举报
回复
up
yefm 2003-03-12
  • 打赏
  • 举报
回复
up
northwolves 2003-03-12
  • 打赏
  • 举报
回复
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

commandbox间移动还须设置其command_press事件
ksmark 2003-03-12
  • 打赏
  • 举报
回复

SendKeys"{Tab}"

Best of luck to you !
山顶洞人-平 2003-03-12
  • 打赏
  • 举报
回复
同意楼上的
Key_Event也可以
Cooly 2003-03-12
  • 打赏
  • 举报
回复
sendkeys "{TAB}"
mathematician 2003-03-12
  • 打赏
  • 举报
回复
Private Sub Text9_KeyPress(KeyAscii As Integer)
If (KeyAscii = vbKeyReturn) Then
SendKeys ("{TAB}")
End If
End Sub

快结帖!
lilimaoming 2003-03-12
  • 打赏
  • 举报
回复
应该是SendKeys{"TAB"},另外也可用例如text1.setfoucus的方法达到同样效果。
horsefly 2003-03-12
  • 打赏
  • 举报
回复
SetKeys{"TAB"}用这个试试
在有回车键被按下时处理一下。

7,763

社区成员

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

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