質問

I feel confused on the Parent of a control and I tried to display the Parent of control by showing it with

MessageBox.Show(unknownParentcontrol.Parent.ToString()); 

but the result display

Project.Form1, Text: System

if its parent is Form1

but it will display like this

System.Windows.Forms.Panel, BorderStyle: System.Windows.Forms.BorderStyle.None

if it is belong to a Panel called pnlUnknown.

May I know how to display exact Parent name of a control even if it belongs to a Panel or other controls from Form?

役に立ちましたか?

解決

Because the exact Parent name info is stored in

unknownParentcontrol.Parent.Name 

but not

unknownParentcontrol.Parent

So we can show the name of Parent with

MessageBox.Show(unknownParentcontrol.Parent.Name.ToString());

By the way,

unknownParentcontrol.Parent

shows the parent container of the control

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top