不需要额外的控件,你处理一下就可以了:Option Explicit Private Sub Form_Load() Dim i As Long For i = 1 To 100 Me.Combo1.AddItem "line " + CStr(i) Next End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) Debug.Print KeyCode Static flag As Boolean If KeyCode = 45 Then If flag = False Then Combo1.SelLength = 1 Else Combo1.SelLength = 0 End If flag = Not flag End If End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Static flag As Boolean If KeyCode = 45 Then If flag = False Then Text1.SelLength = 1 Else Text1.SelLength = 0 End If flag = Not flag End If End Sub
首先将窗口的 KeyPreview 属性设置为 TruePrivate Sub Form_KeyPress(KeyAscii As Integer) Dim lngSelStart As Long
If TypeOf ActiveControl Is TextBox Or TypeOf ActiveControl Is ComboBox Then If ActiveControl.SelStart < Len(ActiveControl.Text) Then lngSelStart = ActiveControl.SelStart ActiveControl.Text = Mid(ActiveControl.Text, 1, ActiveControl.SelStart) & Mid(ActiveControl.Text, ActiveControl.SelStart + 2) ActiveControl.SelStart = lngSelStart End If End If End Sub========================== 免费的学习、交流、源码、工具下载网站,欢迎大家访问! http://www.j2soft.cn/
Private Sub Form_Load()
Dim i As Long
For i = 1 To 100
Me.Combo1.AddItem "line " + CStr(i)
Next
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode
Static flag As Boolean
If KeyCode = 45 Then
If flag = False Then
Combo1.SelLength = 1
Else
Combo1.SelLength = 0
End If
flag = Not flag
End If
End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Static flag As Boolean
If KeyCode = 45 Then
If flag = False Then
Text1.SelLength = 1
Else
Text1.SelLength = 0
End If
flag = Not flag
End If
End Sub
不过,这样有个问题啊,这样每个textbox或者combox都要按一下insert才是改写,能不能让他默认,光标一到textbox(combox)上,就是改写状态呢?因为我录入界面上有好多textbox和combo啊!
请再想想办法!谢谢!!!!!!
Dim lngSelStart As Long
If TypeOf ActiveControl Is TextBox Or TypeOf ActiveControl Is ComboBox Then
If ActiveControl.SelStart < Len(ActiveControl.Text) Then
lngSelStart = ActiveControl.SelStart
ActiveControl.Text = Mid(ActiveControl.Text, 1, ActiveControl.SelStart) & Mid(ActiveControl.Text, ActiveControl.SelStart + 2)
ActiveControl.SelStart = lngSelStart
End If
End If
End Sub==========================
免费的学习、交流、源码、工具下载网站,欢迎大家访问!
http://www.j2soft.cn/