VB中旳文本框要限制输入旳字符数,可以选中这个文本框后,在它的“属性”面板中设置它的MaxLength属性为10,就设定了这个文本框中最多可以输入10个字符。
也可以用代码进行这项设置:
Text1.MaxLength=10
如果设置MaxLength属性为0(默认值),就是不人为限制它的最多字符数,其最大值由VB系统确定:
在MaxLength不设定的默认情况下,单行TextBox和多行TextBox分别能输入的最大字符数是:
单行:2048,多行:32K
你建立个 form1, 里面画个 Combo1,text1 text2 然后把这段代码弄进去代码里面,自己研究下,这个能帮助你解决问题了
Option Explicit
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
lpList As Long) As Long
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" _
(ByVal pwszKLID As String) As Long
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal _
hkl As Long, ByVal lpsz As String, ByVal uBufLen As Long) As Long
Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal _
flags As Long) As Long
Const IME_CONFIG_GENERAL = 1
Const KLF_REORDER = H8
Const KLF_ACTIVATE = H1
Dim la(1 To 16) As Long
Dim ActIme As Long
Private Sub Combo1_Click()
ActIme = la(Combo1.ListIndex + 1)
Debug.Print ActIme
Text1.SetFocus
End Sub
Private Sub Form_Load()
Dim astr As String * 256
Dim bstr As String
Dim x, hMem, i As Long
x = GetKeyboardLayoutList(32, la(1))
Combo1.Clear
If x Then
For i = 1 To x
ImmGetDescription la(i), astr, 256
If InStr(astr, Chr(0)) = 1 Then
bstr = ""
Else
bstr = Left$(astr, InStr(astr, Chr(0)))
End If
If Trim(bstr) = "" Then
Combo1.AddItem "英语(美国)"
Else
Combo1.AddItem bstr
End If
Next i
End If
End Sub
Private Sub Text1_GotFocus()
If Combo1.ListCount 0 Then
ActivateKeyboardLayout ActIme, 1
End If
End Sub
将在文本框中输入内容的语句放在一个可以运行三次的循环语句中。若三次输入都是错误的,直接退出整个程序即可。