我知道,在标准的text控件中(以及其它VB的输入控件中)输入字符时,只能以插入的方法输入(Insert键是无效的)。我想知道,怎样才能实现以改写的方式输入。
要求给出使输入变成改写方式和使输入变回插入方式的代码。
在这儿先谢谢大家,原则上不拆分,分给给出最符合要求和最先给出答案的朋友。

解决方案 »

  1.   

    Private Sub Text1_GotFocus()
         Me.Text1.SelLength = 1
    End SubPrivate 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
        
      

  2.   

    一个按钮,一个textbox:Dim ischange As BooleanPrivate Sub Command1_Click()
    ischange = Not ischange
    Text1.SetFocus
    End SubPrivate Sub Form_Load()
        ischange = False
        Command1.Caption = "文本框输入状态切换"
    End SubPrivate 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
        
      

  3.   

    和和,那么简单的程序,我能看懂:)。下面你那个回答可以不用咯。
    我稍改造了一下:
    Private Sub Text1_GotFocus()
         Me.Text1.SelLength = 1
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
         Me.Text1.SelLength = 1
    End SubPrivate 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控件。
      

  4.   

    最后再次改进:
    Private Sub MaskEdBox1_GotFocus()
    MaskEdBox1.SelLength = 1
    End SubPrivate 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提供思路。