我想让TEXT控件的Maxlength在30之内(中文为15)个,在WIN2000下对于中文字符
却是30!我应怎么做?谢谢!!!!!

解决方案 »

  1.   

    在 text1_change 事件里判断是否有中文字符,有几个,参考如下资料:http://expert.csdn.net/Expert/topic/1995/1995116.xml?temp=.955044
      

  2.   

    那是操作系统的问题。呵呵,好像没办法。98 是 AscII 的代码集,而 Windows 2000 是UniCode 代码集,这个代码集所有字符都占用两个字节,包括英文字母……
      

  3.   

    '控制KeyPress事件
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        KeyAscii = F_iKeyCheck(KeyAscii, Text1.MaxLength)
        'KeyAscii = F_iKeyCheck(KeyAscii, 30)  也行
    End SubPrivate Function F_iKeyCheck(ByVal iKeyAscii As Integer, Optional ByVal iLength As Integer = 0) As Integer
        Dim iRet As Integer
        Dim i As Integer
        Dim S As String
        
        '如果对输入的长度没有限制,就取Text1的长度限制。
        If iLength = 0 Then iLength = Text1.MaxLength        S = Text1.Text
            S = StrConv(S, vbFromUnicode)
            If LenB(S) - Text1.SelLength + LenB(StrConv(Chr(iKeyAscii), vbFromUnicode)) > iLength Then
                iRet = 0
            End If
        F_iKeyCheck = iRet
        
    End Function
      

  4.   

    大概是我没有说清楚问题(抱歉!!!)
    我是要想让TEXT控件(WIN2000及WIN98)的 Maxlength 英文字为30,中文字为15.
    但是在WIN2000下中文字却是30!
    我知道这其中有操作系统的字符集的问题,可是应怎么解决:
    在WIN2000及WIN98下中文字为15,英文字为30.
      

  5.   

    先测试你的软件在什么系统下运行,再决定是使用哪个 MaxLenth,如何?