vb 中parent问题

List1.Parent.Label1.Caption=List1.Parent.List1.ListCount

上面那句话中的“List1.Parent.”必须得有吗?可不可以没有?

可以去掉的:
Label1.Caption = List1.ListCount

List1.Parent是指List1的父对象,比如List1是放在窗体Form1上的,则List1.Parent就是Form1;又比如List1是放在容器控件比如Picture1中的,则List1.Parent就是Picture1。因此
List1.Parent.Label1.Caption=List1.Parent.List1.ListCount

实际上就相当于
Form1.Label1.Caption=Form1.List1.ListCount

由于当前窗体对象是可以省略的,因此
Label1.Caption = List1.ListCount
温馨提示:答案为网友推荐,仅供参考
相似回答