本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 [署名 4.0 国际 (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/deed.zh) 本文作者: 苏洋 创建时间: 2009年01月02日 统计字数: 724字 阅读时间: 2分钟阅读 本文链接: https://soulteary.com/2009/01/02/vb-auto-convert-char-capitalization-lowercase.html ----- # VB 如何自动转换字母的大小写 VB中转换字母大写小写,你可以通过改变KeyAscii数值或者使用Lcase或者Ucase函数来做。 注意:使用Lcase或Ucase后,需要设置一下光标的位置。 自动转换字母的大小写[3种方法] ```vb Private Sub txtCcase_KeyPress(KeyAscii As Integer) If chkConvert(0).Value = 1 Then If KeyAscii > 96 And KeyAscii < 123 Then KeyAscii = (KeyAscii And 223) If chkConvert(1).Value = 1 Then If KeyAscii > 64 And KeyAscii < 91 Then KeyAscii = (KeyAscii Or 32) If chkConvert(2).Value = 1 Then If KeyAscii > 96 And KeyAscii < 123 Then KeyAscii = KeyAscii + 32 If chkConvert(3).Value = 1 Then If KeyAscii > 64 And KeyAscii < 91 Then KeyAscii = KeyAscii - 32 End Sub Private Sub txtCcase_KeyUp(KeyCode As Integer, Shift As Integer) If chkConvert(4).Value = 1 Then txtCcase = UCase$(txtCcase): txtCcase.SelStart = Len(txtCcase) If chkConvert(5).Value = 1 Then txtCcase = LCase$(txtCcase): txtCcase.SelStart = Len(txtCcase) End Sub ```