问题
单项选择题
在窗体上画一个名称为List1的列表框,一个名称为Label1的标签。列表框中显示若干城市的名称。当单击列表框中的某个城市名时,在标签中显示选中城市的名称。下列能正确实现上述功能的程序是
A.Private Sub List1 Click()
Label1.Caption=List1.List-
Index
End Sub
B.Private Sub List1_Click()
Label1.Name=List1. ListIn-
dex
End Sub
C.Private Sub List1 Click()
Label1.Name=List1.Text
End Sub
D.Private Sub List1_Click()
Label1.Caption=List1.Text
End Sub
答案
参考答案:D
解析: 要实现在标签上显示选中城市的名称,很容易想到需使用标签的Caption属性。标签的Caption属性我们前面已经介绍过。怎样获取选中城市的名称要结合列表List的属性来考虑。其中Text属性表示最后选中列表项的内容。故正确语句应为Label1.Caption=List1.Text。选项D正确。