一个小问题:怎么在text控件中实现改写方式?

weill 2003-10-21 10:07:46
我知道,在标准的text控件中(以及其它VB的输入控件中)输入字符时,只能以插入的方法输入(Insert键是无效的)。我想知道,怎样才能实现以改写的方式输入。
要求给出使输入变成改写方式和使输入变回插入方式的代码。
在这儿先谢谢大家,原则上不拆分,分给给出最符合要求和最先给出答案的朋友。
...全文
29 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
weill 2003-10-21
  • 打赏
  • 举报
回复
最后再次改进:
Private Sub MaskEdBox1_GotFocus()
MaskEdBox1.SelLength = 1
End Sub

Private Sub MaskEdBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode >= 37 And KeyCode <= 40) And MaskEdBox1.SelStart > 0 Then
MaskEdBox1.SelStart = MaskEdBox1.SelStart - 1
End If
MaskEdBox1.SelLength = 1
End Sub

这样就比较好了,在这儿我用的是MaskEdBox控件,text控件上应也一样。
谢谢rainstormmaster提供思路。
weill 2003-10-21
  • 打赏
  • 举报
回复
和和,答案是基本令人满意的,我看看有没有别的人有更好的主意,如果没有,下午5:00前结贴:)。
weill 2003-10-21
  • 打赏
  • 举报
回复
和和,那么简单的程序,我能看懂:)。下面你那个回答可以不用咯。
我稍改造了一下:
Private Sub Text1_GotFocus()
Me.Text1.SelLength = 1
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Me.Text1.SelLength = 1
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
Me.Text1.SelStart = Me.Text1.SelStart - 1
End If

Me.Text1.SelLength = 1
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Text1.SelLength = 1
End Sub
不过,感觉效果不是非常好,有点儿滞的。不知是不是还有别的更好的方法,比如用API,或是别的VB标准控件代替text控件。
rainstormmaster 2003-10-21
  • 打赏
  • 举报
回复
或者试试进行子类处理
rainstormmaster 2003-10-21
  • 打赏
  • 举报
回复
//基本不错,但在用左右光标键移动光标位置时,稍不令人满意

只能这样了,要不就使用第3方控件
weill 2003-10-21
  • 打赏
  • 举报
回复
基本不错,但在用左右光标键移动光标位置时,稍不令人满意。
rainstormmaster 2003-10-21
  • 打赏
  • 举报
回复
一个按钮,一个textbox:

Dim ischange As Boolean

Private Sub Command1_Click()
ischange = Not ischange
Text1.SetFocus
End Sub

Private Sub Form_Load()
ischange = False
Command1.Caption = "文本框输入状态切换"
End Sub

Private Sub Text1_GotFocus()
If ischange Then
Me.Text1.SelLength = 1
Else
Me.Text1.SelLength = 0
End If
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If ischange Then
Me.Text1.SelLength = 1
Else
Me.Text1.SelLength = 0
End If
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If ischange Then
Me.Text1.SelLength = 1
Else
Me.Text1.SelLength = 0
End If
End Sub

rainstormmaster 2003-10-21
  • 打赏
  • 举报
回复
Private Sub Text1_GotFocus()
Me.Text1.SelLength = 1
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Text1.SelLength = 1
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Text1.SelLength = 1
End Sub

1,485

社区成员

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

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