先有一文本框,其初始化text为“aaa”
显示给用户输入的时候,要求用户不能修改“aaa"的这个文本,但可以在后面输入其他内容。
有没有解决办法?

解决方案 »

  1.   

    方法一:
    获得焦点时除掉"aaa"
    失处焦点时添加进去
      

  2.   

    方法二:
    在文本框前贴一个caption为"aaa"的标签,文本框中不写“aaa”。
      

  3.   

    方法三:改用maskedit控件。
      

  4.   

    Private Sub Text1_Change()
    If Len(Text1.Text) <= 3 Then
        Text1.Text = "aaa"
        Text1.SelStart = Len(Text1)
    Else
        If Mid(Text1.Text, 1, 3) <> "aaa" Then
            Text1.Text = "aaa"
            Text1.SelStart = Len(Text1)
        End If
    End If
    End Sub
      

  5.   

    在文本框前贴一个caption为"aaa"的标签,文本框中不写“aaa”。在文本框前贴一个caption为"aaa"的标签,文本框中不写“aaa”。
    我同意这两种方法。
      

  6.   

    tztz520(午夜逛街)的想法不错,我试试先,感谢各位。
      

  7.   

    一个更好的方法
    其中的3代表需要控制字符的长度Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 46 And Text1.SelStart < 3 Then
            KeyCode = 0
        End If
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 8 And Text1.SelStart = 3 Then KeyAscii = 0
        If Text1.SelStart >= 3 Then
        Else
            KeyAscii = 0
        End If
    End Sub
      

  8.   

    >>步骤1----建立新工程,在窗体上放置一个TextBox;
    >>步骤2----在窗体上创建一菜单,设其Name = a;Visible = false;
    >>步骤3----编写如下代码:
    Private Sub Text1_MouseDown(Button As Integer, Shift _
    As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
    Text1.Enabled = False
    Text1.Enabled = True
    PopupMenu a
    End If
    End Sub