Find Parent Control of Control.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Some one help me out.

I have a windows form.I added Panel to a windows form.
I put a textbox in a Panel.

When ever I try to get Parent of textbox. its always returns me the handle of Form not the panel.

Is there any way to get the Parent Control of a control on the Form?
Am I missing anything?

Thanks

dinoo
 
So I started up a new VB Windows Forms project, put a panel on the form and
a textbox inside it, put the following code in the textbox's click handler,
and it worked just fine. Printed out

"TextBox1's container: Panel1"

just as expected.

Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Click

Dim ctl As TextBox = CType(sender, TextBox)
Debug.WriteLine(ctl.Name + "'s container: " + ctl.Parent.Name)

End Sub

I can't say what's happening in your case, but this test worked just as it
should.

Good luck,
Tom Dacon
Dacon Software Consulting
 
Dinoo,

In addition to Tom

MessageBox.Show(TextBox1.Parent.Parent.Name)
Gives for me "Form1"
MessageBox.Show(TextBox1.Parent.Name)
Gives for me "Panel1"

I hope this helps?

Cor
 
Back
Top