单选题
窗体上有一个名称为Text1的文本框,要求在获得焦点时选中文本框中所有内容,以下能实现该功能的事件过程是
A、
Private Sub Text1_Change() Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub
B、
Private Sub Text1_LostFocus() Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub
C、
Private Sub Text1_GotFocus() Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub
D、
Private Sub Text1_SetFocus() Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub
【正确答案】
C
【答案解析】
解析:文本框中LostFocus事件是当一个对象失去焦点时触发该事件。当按Tab键或用鼠标单击另一个对象时,都会使焦点所在对象失去焦点。GotFocus事件与LostFocus事件正好相反,当一个对象获得焦点时触发该事件。Change事件是当用户在文本框中输入内容或者程序代码中给Text属性赋新值时触发该事件。故正确答案为选项C。
提交答案
关闭