我的格式为:###-###-###-### Private Sub T_Change() If Len(T.Text) = 3 Then T.Text = T.Text + "-" T.SelStart = Len(T.Text) End If If Len(T.Text) = 7 Then T.Text = T.Text + "-" T.SelStart = Len(T.Text) End If If Len(T.Text) = 11 Then T.Text = T.Text + "-" T.SelStart = Len(T.Text) End IfEnd SubPrivate Sub T_KeyPress(KeyAscii As Integer) If Len(T.Text) >= 15 Then KeyAscii = 0 End If End Sub
三个Textbox+两个Label+Textbox的事件处理
回Boible() ( ) 信誉:98 2002-6-5 10:11:56 得分:0
但是,那样做字符串长度就是定长的了,要使字符串长度可变,特别是每一节的长度要变应该如何是好呢?
我对这个问题只有一个构思,不知道能不能行: 用hengxin54(恒欣)的例子来说的话,就是让Len(T.Text) = x(Dim x As Integer),当x = 你需要的长度时用回车结束,然后再触发: T.Text = T.Text + "-" T.SelStart = Len(T.Text) 这是在网吧写的,没法试,抱歉:)
Private Sub T_Change()
If Len(T.Text) = 3 Then
T.Text = T.Text + "-"
T.SelStart = Len(T.Text)
End If
If Len(T.Text) = 7 Then
T.Text = T.Text + "-"
T.SelStart = Len(T.Text)
End If
If Len(T.Text) = 11 Then
T.Text = T.Text + "-"
T.SelStart = Len(T.Text)
End IfEnd SubPrivate Sub T_KeyPress(KeyAscii As Integer)
If Len(T.Text) >= 15 Then
KeyAscii = 0
End If
End Sub
但是,那样做字符串长度就是定长的了,要使字符串长度可变,特别是每一节的长度要变应该如何是好呢?
我对这个问题只有一个构思,不知道能不能行:
用hengxin54(恒欣)的例子来说的话,就是让Len(T.Text) = x(Dim x As Integer),当x = 你需要的长度时用回车结束,然后再触发:
T.Text = T.Text + "-"
T.SelStart = Len(T.Text)
这是在网吧写的,没法试,抱歉:)
这是非常简单的解决问题的方法(逻辑简单),可解决提出的问题,可为什么还在问:
“但是,那样做字符串长度就是定长的了,要使字符串长度可变,特别是每一节的长度要变应该如何是好呢?”
用一个Label(3D样式)作背景,另外加三个文本框(无边框、平面)嵌入在相应的位置,两个作为分割的label(caption="-")放在三个文本框中间,处理三个文本框的事件...