问题 单项选择题

假定一个表单里有一个文本框Text1和一个命令按钮组CommandGroup1,命令按钮组是一个容器对象,其中包含Cbmmand1和Command2两个命令按钮,如果要在Command1命令按钮的某个方法中访问文本框的Value属性值,下面表达式中正确的是( )。

A) This.ThisForm.Text1.Value
B) This.ParentParent.Text1.Value
C) ParentParent.Text1.Value
D) ThisParent.Text1.Value

答案

参考答案:B

解析: 在对象的嵌套层次关系中,要引用其中的某个对象,需要指明对象在嵌套层次中的位置。本题要求在Command1的某个方法中访问文本框的Value属性值,应该选B)选项This.Parent.Parent.Text1.Value,其中This表示当前对象Command1;This.Parent表示当前对象Command1的父对象,即命令按钮组CommandGroup1;This.Parent.Parent表示命令按钮组的父对象,即表单;This.Parent.Parent.Text1.Value表示表单中的文本框的值。

单项选择题
名词解释