如何按一个快捷键,在textbox中插入字符串?

SwordMan2001 2003-09-24 02:31:30
就像记事本程序那样,按F5,插入日期和时间,特点是:
1.在光标处插入,插入后光标停在日期时间之后.
2.不是用SendKeys,否则会发现字一个一个弹出来.

另外,如果我没有用菜单,怎么能捕获和处理F5这样的键呢?
...全文
79 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SwordMan2001 2003-09-29
  • 打赏
  • 举报
回复
不错不错
whoiszm 2003-09-24
  • 打赏
  • 举报
回复

Option Explicit
利用text 里的 keydown和Text1.SelText就可以了!
Private Sub Form_Load()
Text1 = "adfhadhadf"
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF5 Then
Text1.SelText = "1354654"'你要插入的字符串
End If
End Sub
lxcc 2003-09-24
  • 打赏
  • 举报
回复
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF5 Then
Text1.SelStart = Len(Text1)
Text1.SelText = Now
End If
End Sub
佛的光辉 2003-09-24
  • 打赏
  • 举报
回复
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim s As String
Dim i As Long
If KeyCode = vbKeyF5 Then
s = Left(Text1.Text, Text1.SelStart)
s = s & Date
i = Len(s)
s = s & Right(Text1.Text, Len(Text1.Text) - Text1.SelStart)
Text1.Text = s
Text1.SelStart = i
End If
End Sub

1,453

社区成员

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

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