Inheritance Question in VB.NET

G

Guest

Hi
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2 is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no knowledge
of the child class and should be able to instantiate a child class object.

Can someone explain this? Also, can someone suggest a better way to exchange
data between 2 forms.

Regards

Saumitra
 
R

Robin Tucker

Ahhh, what you are talking about "parent<-->child" relationship between
forms is not the same as inheritance. In OOP, inheritence refers to the
fact that the methods, properties and member variables of a class are
"inherited" by the new class at compile time, whereas the Window Parent <->
Child relationship purely refers to the fact that one recieves messages from
the other. Your Form1 will contain a reference to your Form2 and your Form2
will contain a reference (parent) to your Form1. Both of the classes you
are using are derived from Windows.Forms, not from each other.
 
H

Herfried K. Wagner [MVP]

Saumitra said:
I am new to VB.NET and I am trying to figure out how to exchange data
between 2 forms based on parent-child relationship between 2 forms. Form2
is
child of form1. In form1.vb, I am doing
Dim t As New Form2
t.Show()

This is really strange to me because by OOPS, a base class has no
knowledge
of the child class and should be able to instantiate a child class object.

Inheritance <> Parent <-> child relationship!

What you need is a reference to your instance of the form you want to
manipulate. There are different ways to make this reference available, for
example, by passing it in method parameters or assigning it to properties,
or implementing the Singleton design pattern if there can be only one
instance of a form:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top