Reputation: 4125
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?
Upvotes: 0
Views: 35
Reputation: 4125
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
Upvotes: 2