Question

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?

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top