问题 单项选择题

在窗体上画一个名称为Text1的文本框,要求文本框只能接收大写字母的输入。以下能实现该操作的事件过程是

A.Private SubText1_KeyPress(KeyAscii As Integer)
If KeyAscii<65 or KeyAscii>90 Then

MsgBox“请输入大写字母”

KeyAscii=0

End If

End Sub
B. Private Sub Text1_KeyDown( KeyCode As Integer,Shift As Integer)

If KeyCode < 65 or KeyCode > 90 Then

Msgbox“请输入大写字母”
KeyCode = 0

End If

End Sub
C. Private SuB Text1_MouseDown( Button AS Integer,_

Shift As lnteger,X As Single,Y As Single)

If Asc ( Text1. Text) < 65 or Asc ( Text1.Text) > 90 Then

Msgbox“请输入大写字母”

End If

End Sub
D. Private Sub Text1_Change(
)

If Asc(Text1.Text) >64 And Asc(Text1.Text) >9l Then

Msgbox“请输入大写字母”


End lf

End Sub

答案

参考答案:A

解析: KeyPress的参数KeyAscii对应不同的字符,它与KeyDown的参数 KeyCode有本质上的区别。KeyCode对应键的ASCII码,不区分大小写。根据题目要求,文本框的事件要区分字母的大小写。MouseDown表示是否按下鼠标,Change表示文本框内容是否发生变化。

实验题
问答题