How to Create a Parent-Child Relationship Using VB.NET

VB.NET works with a parent-child relationship, so programmers can work with Windows forms and the "child" controls the forms contain. Each container you add to the Windows form can contain controls, and these containers are the parents of the contained controls. You can work up or down the hierarchy in a VB.NET program to obtain the parent or child controls.

Instructions

    • 1

      Open the Visual Studio software in the Windows ".NET Framework" program group. Open your VB.NET Windows project.

    • 2

      Double-click the form you want to use to create the parent-child relationship. Drag and drop a container to the form. For instance, the "Panel" control is a simple container that lets you contain any VB.NET controls. When you add a panel to the form, the form is the panel's parent and the controls within the panel are the child controls.

    • 3

      Drag and drop a control from the toolbox to the panel container. For instance, drag and drop a text box control to the container. The text box parent is the panel, but the text box does not contain any controls, so it has no children.

    • 4

      Double-click the VB.NET code file to work with the parent-child relationships. For instance, type the following code to display the parent for the text box:

      MsgBox textbox1.Parent.ToString()

Related Searches:

References

Comments

Related Ads

Featured