Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > Multiple Forms - VB.Net

Reply
Thread Tools

Multiple Forms - VB.Net

 
 
Quest
Guest
Posts: n/a
 
      09-30-2003
Hi,



I would appreciate any input on this problem. (Visual Basic.NET Windows
Application)



Facts:

I have created a new windows project from Visual Studio.net called
'Database2'.

On the default created form called Form1 I have created a textbox called
TextBox1 (at design time)

I have created from Solution Explorer a new Module called Module1 and a new
form called Form2. (at design time)



Problem:

How do I access Textbox1 residing on Form1 FROM either Form2 or Module1. It
must however, reference the ORIGINAL instance of the form created at design
time (not a new instance).



I have tried the following (both give an error message) code on Form2 :



Database2.form1.Textbox1.text="test"

Form1.Textbox1.text="test"



I can refer to a new instance of the form1 with the following code



Dim myform as new Form1



But then it would NOT be referring to the ORGINAL instance of the form.



Any ideas on how to access the Textbox1 on Form1 created at design time
without instantiating a new instance of Form1?



Thank you.


 
Reply With Quote
 
 
 
 
Kumar
Guest
Posts: n/a
 
      09-30-2003
If you open the code for Form1, it may look like the
following:

Public Class Form1
Inherits System.Windows.Forms.Form
.....
....

Which means that the form you see on the designer is
nothing by an instance of the Form1 class. Visual Studio
does a special job for you to show the form in design
time. If you want refer any form you need to create an
instance of it.

I hope this helps.

-Kumar

>-----Original Message-----
>Hi,
>
>
>
>I would appreciate any input on this problem. (Visual

Basic.NET Windows
>Application)
>
>
>
>Facts:
>
>I have created a new windows project from Visual

Studio.net called
>'Database2'.
>
>On the default created form called Form1 I have created a

textbox called
>TextBox1 (at design time)
>
>I have created from Solution Explorer a new Module called

Module1 and a new
>form called Form2. (at design time)
>
>
>
>Problem:
>
>How do I access Textbox1 residing on Form1 FROM either

Form2 or Module1. It
>must however, reference the ORIGINAL instance of the form

created at design
>time (not a new instance).
>
>
>
>I have tried the following (both give an error message)

code on Form2 :
>
>
>
>Database2.form1.Textbox1.text="test"
>
>Form1.Textbox1.text="test"
>
>
>
>I can refer to a new instance of the form1 with the

following code
>
>
>
>Dim myform as new Form1
>
>
>
>But then it would NOT be referring to the ORGINAL

instance of the form.
>
>
>
>Any ideas on how to access the Textbox1 on Form1 created

at design time
>without instantiating a new instance of Form1?
>
>
>
>Thank you.
>
>
>.
>

 
Reply With Quote
 
 
 
 
Quest
Guest
Posts: n/a
 
      10-01-2003
Ok. But the point is this : When you run the application, you are viewing
the instance of the form that you created at design time. The question is,
how do you access this SAME instance in code ??
If I can access the same instance of the form in code, then I can access the
texbox1 on form1 that the user first sees when the application is run.

"Kumar" <(E-Mail Removed)> wrote in message
news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> If you open the code for Form1, it may look like the
> following:
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> ....
> ...
>
> Which means that the form you see on the designer is
> nothing by an instance of the Form1 class. Visual Studio
> does a special job for you to show the form in design
> time. If you want refer any form you need to create an
> instance of it.
>
> I hope this helps.
>
> -Kumar
>
> >-----Original Message-----
> >Hi,
> >
> >I would appreciate any input on this problem. (Visual

> Basic.NET Windows
> >Application)
> >
> >Facts:
> >
> >I have created a new windows project from Visual

> Studio.net called 'Database2'.


> >On the default created form called Form1 I have created a

> textbox called TextBox1 (at design time)


> >I have created from Solution Explorer a new Module called

> Module1 and a new
> >form called Form2. (at design time)
> >
> >Problem:
> >
> >How do I access Textbox1 residing on Form1 FROM either

> Form2 or Module1. It
> >must however, reference the ORIGINAL instance of the form

> created at design
> >time (not a new instance).
> >
> >I have tried the following (both give an error message)

> code on Form2 :
> >
> >Database2.form1.Textbox1.text="test"
> >Form1.Textbox1.text="test"
> >
> >I can refer to a new instance of the form1 with the

> following code
> >
> >Dim myform as new Form1


> >But then it would NOT be referring to the ORGINAL

> instance of the form.
> >
> >Any ideas on how to access the Textbox1 on Form1 created

> at design time without instantiating a new instance of Form1?
> >
> >Thank you.



 
Reply With Quote
 
Jim Parker
Guest
Posts: n/a
 
      10-01-2003
The controls on forms are no longer public as they were in VB6.
Create public properties on Form1 to share the info that is desired to share
(textBox1.Text, whatever).
Create a property of type Form1 on Form2, and set it to the already created
instance of Form1 when an instance of Form2 is created.
Then you can easily access the public items on Form1 from Form2.

JD.

"Quest" <(E-Mail Removed)> wrote in message
news:Uszeb.831$(E-Mail Removed)...
> Ok. But the point is this : When you run the application, you are viewing
> the instance of the form that you created at design time. The question is,
> how do you access this SAME instance in code ??
> If I can access the same instance of the form in code, then I can access

the
> texbox1 on form1 that the user first sees when the application is run.
>
> "Kumar" <(E-Mail Removed)> wrote in message
> news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > If you open the code for Form1, it may look like the
> > following:
> >
> > Public Class Form1
> > Inherits System.Windows.Forms.Form
> > ....
> > ...
> >
> > Which means that the form you see on the designer is
> > nothing by an instance of the Form1 class. Visual Studio
> > does a special job for you to show the form in design
> > time. If you want refer any form you need to create an
> > instance of it.
> >
> > I hope this helps.
> >
> > -Kumar
> >
> > >-----Original Message-----
> > >Hi,
> > >
> > >I would appreciate any input on this problem. (Visual

> > Basic.NET Windows
> > >Application)
> > >
> > >Facts:
> > >
> > >I have created a new windows project from Visual

> > Studio.net called 'Database2'.

>
> > >On the default created form called Form1 I have created a

> > textbox called TextBox1 (at design time)

>
> > >I have created from Solution Explorer a new Module called

> > Module1 and a new
> > >form called Form2. (at design time)
> > >
> > >Problem:
> > >
> > >How do I access Textbox1 residing on Form1 FROM either

> > Form2 or Module1. It
> > >must however, reference the ORIGINAL instance of the form

> > created at design
> > >time (not a new instance).
> > >
> > >I have tried the following (both give an error message)

> > code on Form2 :
> > >
> > >Database2.form1.Textbox1.text="test"
> > >Form1.Textbox1.text="test"
> > >
> > >I can refer to a new instance of the form1 with the

> > following code
> > >
> > >Dim myform as new Form1

>
> > >But then it would NOT be referring to the ORGINAL

> > instance of the form.
> > >
> > >Any ideas on how to access the Textbox1 on Form1 created

> > at design time without instantiating a new instance of Form1?
> > >
> > >Thank you.

>
>



 
Reply With Quote
 
Jim Parker
Guest
Posts: n/a
 
      10-01-2003
BTW,
This answers your question, but it is not a good OO practice.

JD.

"Jim Parker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The controls on forms are no longer public as they were in VB6.
> Create public properties on Form1 to share the info that is desired to

share
> (textBox1.Text, whatever).
> Create a property of type Form1 on Form2, and set it to the already

created
> instance of Form1 when an instance of Form2 is created.
> Then you can easily access the public items on Form1 from Form2.
>
> JD.
>
> "Quest" <(E-Mail Removed)> wrote in message
> news:Uszeb.831$(E-Mail Removed)...
> > Ok. But the point is this : When you run the application, you are

viewing
> > the instance of the form that you created at design time. The question

is,
> > how do you access this SAME instance in code ??
> > If I can access the same instance of the form in code, then I can access

> the
> > texbox1 on form1 that the user first sees when the application is run.
> >
> > "Kumar" <(E-Mail Removed)> wrote in message
> > news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > > If you open the code for Form1, it may look like the
> > > following:
> > >
> > > Public Class Form1
> > > Inherits System.Windows.Forms.Form
> > > ....
> > > ...
> > >
> > > Which means that the form you see on the designer is
> > > nothing by an instance of the Form1 class. Visual Studio
> > > does a special job for you to show the form in design
> > > time. If you want refer any form you need to create an
> > > instance of it.
> > >
> > > I hope this helps.
> > >
> > > -Kumar
> > >
> > > >-----Original Message-----
> > > >Hi,
> > > >
> > > >I would appreciate any input on this problem. (Visual
> > > Basic.NET Windows
> > > >Application)
> > > >
> > > >Facts:
> > > >
> > > >I have created a new windows project from Visual
> > > Studio.net called 'Database2'.

> >
> > > >On the default created form called Form1 I have created a
> > > textbox called TextBox1 (at design time)

> >
> > > >I have created from Solution Explorer a new Module called
> > > Module1 and a new
> > > >form called Form2. (at design time)
> > > >
> > > >Problem:
> > > >
> > > >How do I access Textbox1 residing on Form1 FROM either
> > > Form2 or Module1. It
> > > >must however, reference the ORIGINAL instance of the form
> > > created at design
> > > >time (not a new instance).
> > > >
> > > >I have tried the following (both give an error message)
> > > code on Form2 :
> > > >
> > > >Database2.form1.Textbox1.text="test"
> > > >Form1.Textbox1.text="test"
> > > >
> > > >I can refer to a new instance of the form1 with the
> > > following code
> > > >
> > > >Dim myform as new Form1

> >
> > > >But then it would NOT be referring to the ORGINAL
> > > instance of the form.
> > > >
> > > >Any ideas on how to access the Textbox1 on Form1 created
> > > at design time without instantiating a new instance of Form1?
> > > >
> > > >Thank you.

> >
> >

>
>



 
Reply With Quote
 
Quest
Guest
Posts: n/a
 
      10-01-2003
Thank you.
I think you have the right idea. With reference to your quote where you say
"Create a property of type Form1 on Form2, and set it to the already created
instance of Form1 ....", My question still stands as to how you access that
instance of Form1 in code ?
Remember, that Form1 is a 'type' and not an instance. Therefore we are
trying to access the instance of form1 that is automatically created by VB
at runtime that is based on our design time creation of Form1.

In form2, I have added the following code :

Public Property myForm() As Form1
Get

myForm = Form1

End Get

Set(ByVal Value As Form1)

End Set

End Property

This gives an error message that Form1 is a type ! How do I access the
instance of Form1 from Form2 ?




"Jim Parker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The controls on forms are no longer public as they were in VB6.
> Create public properties on Form1 to share the info that is desired to

share
> (textBox1.Text, whatever).
> Create a property of type Form1 on Form2, and set it to the already

created
> instance of Form1 when an instance of Form2 is created.
> Then you can easily access the public items on Form1 from Form2.
>
> JD.
>
> "Quest" <(E-Mail Removed)> wrote in message
> news:Uszeb.831$(E-Mail Removed)...
> > Ok. But the point is this : When you run the application, you are

viewing
> > the instance of the form that you created at design time. The question

is,
> > how do you access this SAME instance in code ??
> > If I can access the same instance of the form in code, then I can access

> the
> > texbox1 on form1 that the user first sees when the application is run.
> >
> > "Kumar" <(E-Mail Removed)> wrote in message
> > news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > > If you open the code for Form1, it may look like the
> > > following:
> > >
> > > Public Class Form1
> > > Inherits System.Windows.Forms.Form
> > > ....
> > > ...
> > >
> > > Which means that the form you see on the designer is
> > > nothing by an instance of the Form1 class. Visual Studio
> > > does a special job for you to show the form in design
> > > time. If you want refer any form you need to create an
> > > instance of it.
> > >
> > > I hope this helps.
> > >
> > > -Kumar
> > >
> > > >-----Original Message-----
> > > >Hi,
> > > >
> > > >I would appreciate any input on this problem. (Visual
> > > Basic.NET Windows
> > > >Application)
> > > >
> > > >Facts:
> > > >
> > > >I have created a new windows project from Visual
> > > Studio.net called 'Database2'.

> >
> > > >On the default created form called Form1 I have created a
> > > textbox called TextBox1 (at design time)

> >
> > > >I have created from Solution Explorer a new Module called
> > > Module1 and a new
> > > >form called Form2. (at design time)
> > > >
> > > >Problem:
> > > >
> > > >How do I access Textbox1 residing on Form1 FROM either
> > > Form2 or Module1. It
> > > >must however, reference the ORIGINAL instance of the form
> > > created at design
> > > >time (not a new instance).
> > > >
> > > >I have tried the following (both give an error message)
> > > code on Form2 :
> > > >
> > > >Database2.form1.Textbox1.text="test"
> > > >Form1.Textbox1.text="test"
> > > >
> > > >I can refer to a new instance of the form1 with the
> > > following code
> > > >
> > > >Dim myform as new Form1

> >
> > > >But then it would NOT be referring to the ORGINAL
> > > instance of the form.
> > > >
> > > >Any ideas on how to access the Textbox1 on Form1 created
> > > at design time without instantiating a new instance of Form1?
> > > >
> > > >Thank you.

> >
> >

>
>



 
Reply With Quote
 
Jim Parker
Guest
Posts: n/a
 
      10-01-2003
You wrote:
> Public Property myForm() As Form1
> Get
>
> myForm = Form1
>
> End Get


No, that won't work.
Keep in mind that this blows in the face of good OO practices...
Here is a crude example in C#; in VB.Net it would be very similar.

In Form1, the form that is already instantiated:

private Form2 frmTest;
private void button1_Click(object sender, System.EventArgs e)
{
frmTest = new Form2();
frmTest.MyForm(this);
frmTest.Show();
}

In Form2, which is instantiated from Form1:

private Form1 frmMyForm;
public void MyForm(Form1 frmIn)
{
frmMyForm = frmIn;
}

Then in the instance of Form2 you can access anything declared as public in
Form1 by accessing it as frmMyForm.

JD.



"Quest" <(E-Mail Removed)> wrote in message
news:kYBeb.1149$(E-Mail Removed)...
> Thank you.
> I think you have the right idea. With reference to your quote where you

say
> "Create a property of type Form1 on Form2, and set it to the already

created
> instance of Form1 ....", My question still stands as to how you access

that
> instance of Form1 in code ?
> Remember, that Form1 is a 'type' and not an instance. Therefore we are
> trying to access the instance of form1 that is automatically created by VB
> at runtime that is based on our design time creation of Form1.
>
> In form2, I have added the following code :
>
> Public Property myForm() As Form1
> Get
>
> myForm = Form1
>
> End Get
>
> Set(ByVal Value As Form1)
>
> End Set
>
> End Property
>
> This gives an error message that Form1 is a type ! How do I access the
> instance of Form1 from Form2 ?
>
>
>
>
> "Jim Parker" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > The controls on forms are no longer public as they were in VB6.
> > Create public properties on Form1 to share the info that is desired to

> share
> > (textBox1.Text, whatever).
> > Create a property of type Form1 on Form2, and set it to the already

> created
> > instance of Form1 when an instance of Form2 is created.
> > Then you can easily access the public items on Form1 from Form2.
> >
> > JD.
> >
> > "Quest" <(E-Mail Removed)> wrote in message
> > news:Uszeb.831$(E-Mail Removed)...
> > > Ok. But the point is this : When you run the application, you are

> viewing
> > > the instance of the form that you created at design time. The question

> is,
> > > how do you access this SAME instance in code ??
> > > If I can access the same instance of the form in code, then I can

access
> > the
> > > texbox1 on form1 that the user first sees when the application is run.
> > >
> > > "Kumar" <(E-Mail Removed)> wrote in message
> > > news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > > > If you open the code for Form1, it may look like the
> > > > following:
> > > >
> > > > Public Class Form1
> > > > Inherits System.Windows.Forms.Form
> > > > ....
> > > > ...
> > > >
> > > > Which means that the form you see on the designer is
> > > > nothing by an instance of the Form1 class. Visual Studio
> > > > does a special job for you to show the form in design
> > > > time. If you want refer any form you need to create an
> > > > instance of it.
> > > >
> > > > I hope this helps.
> > > >
> > > > -Kumar
> > > >
> > > > >-----Original Message-----
> > > > >Hi,
> > > > >
> > > > >I would appreciate any input on this problem. (Visual
> > > > Basic.NET Windows
> > > > >Application)
> > > > >
> > > > >Facts:
> > > > >
> > > > >I have created a new windows project from Visual
> > > > Studio.net called 'Database2'.
> > >
> > > > >On the default created form called Form1 I have created a
> > > > textbox called TextBox1 (at design time)
> > >
> > > > >I have created from Solution Explorer a new Module called
> > > > Module1 and a new
> > > > >form called Form2. (at design time)
> > > > >
> > > > >Problem:
> > > > >
> > > > >How do I access Textbox1 residing on Form1 FROM either
> > > > Form2 or Module1. It
> > > > >must however, reference the ORIGINAL instance of the form
> > > > created at design
> > > > >time (not a new instance).
> > > > >
> > > > >I have tried the following (both give an error message)
> > > > code on Form2 :
> > > > >
> > > > >Database2.form1.Textbox1.text="test"
> > > > >Form1.Textbox1.text="test"
> > > > >
> > > > >I can refer to a new instance of the form1 with the
> > > > following code
> > > > >
> > > > >Dim myform as new Form1
> > >
> > > > >But then it would NOT be referring to the ORGINAL
> > > > instance of the form.
> > > > >
> > > > >Any ideas on how to access the Textbox1 on Form1 created
> > > > at design time without instantiating a new instance of Form1?
> > > > >
> > > > >Thank you.
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
General Protection Fault
Guest
Posts: n/a
 
      10-01-2003
If Form1 is creating Form2, give Form2 an overloaded constructor that takes
a reference to Form1. Either that or use a callback with a delegate.

You can't reference Form1.xxx or Form2.xxx because they're not static
members. You need an actual instance.

"Quest" <(E-Mail Removed)> wrote in message
news:CDheb.1018$(E-Mail Removed)...
> Hi,
>
>
>
> I would appreciate any input on this problem. (Visual Basic.NET Windows
> Application)
>
>
>
> Facts:
>
> I have created a new windows project from Visual Studio.net called
> 'Database2'.
>
> On the default created form called Form1 I have created a textbox called
> TextBox1 (at design time)
>
> I have created from Solution Explorer a new Module called Module1 and a

new
> form called Form2. (at design time)
>
>
>
> Problem:
>
> How do I access Textbox1 residing on Form1 FROM either Form2 or Module1.

It
> must however, reference the ORIGINAL instance of the form created at

design
> time (not a new instance).
>
>
>
> I have tried the following (both give an error message) code on Form2 :
>
>
>
> Database2.form1.Textbox1.text="test"
>
> Form1.Textbox1.text="test"
>
>
>
> I can refer to a new instance of the form1 with the following code
>
>
>
> Dim myform as new Form1
>
>
>
> But then it would NOT be referring to the ORGINAL instance of the form.
>
>
>
> Any ideas on how to access the Textbox1 on Form1 created at design time
> without instantiating a new instance of Form1?
>
>
>
> Thank you.
>
>



 
Reply With Quote
 
Quest
Guest
Posts: n/a
 
      10-01-2003
Yes it does work !!!
Thank you.

Lesson to be learnt here is that you can pass the instance of the Form1 as a
parameter, in this case we have used MyForm(this) or in VB.NET it is
MyForm(Me). Great.
Once again thank you for the insight.

"Jim Parker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You wrote:
> > Public Property myForm() As Form1
> > Get
> >
> > myForm = Form1
> >
> > End Get

>
> No, that won't work.
> Keep in mind that this blows in the face of good OO practices...
> Here is a crude example in C#; in VB.Net it would be very similar.
>
> In Form1, the form that is already instantiated:
>
> private Form2 frmTest;
> private void button1_Click(object sender, System.EventArgs e)
> {
> frmTest = new Form2();
> frmTest.MyForm(this);
> frmTest.Show();
> }
>
> In Form2, which is instantiated from Form1:
>
> private Form1 frmMyForm;
> public void MyForm(Form1 frmIn)
> {
> frmMyForm = frmIn;
> }
>
> Then in the instance of Form2 you can access anything declared as public

in
> Form1 by accessing it as frmMyForm.
>
> JD.
>
>
>
> "Quest" <(E-Mail Removed)> wrote in message
> news:kYBeb.1149$(E-Mail Removed)...
> > Thank you.
> > I think you have the right idea. With reference to your quote where you

> say
> > "Create a property of type Form1 on Form2, and set it to the already

> created
> > instance of Form1 ....", My question still stands as to how you access

> that
> > instance of Form1 in code ?
> > Remember, that Form1 is a 'type' and not an instance. Therefore we are
> > trying to access the instance of form1 that is automatically created by

VB
> > at runtime that is based on our design time creation of Form1.
> >
> > In form2, I have added the following code :
> >
> > Public Property myForm() As Form1
> > Get
> >
> > myForm = Form1
> >
> > End Get
> >
> > Set(ByVal Value As Form1)
> >
> > End Set
> >
> > End Property
> >
> > This gives an error message that Form1 is a type ! How do I access the
> > instance of Form1 from Form2 ?
> >
> >
> >
> >
> > "Jim Parker" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > The controls on forms are no longer public as they were in VB6.
> > > Create public properties on Form1 to share the info that is desired to

> > share
> > > (textBox1.Text, whatever).
> > > Create a property of type Form1 on Form2, and set it to the already

> > created
> > > instance of Form1 when an instance of Form2 is created.
> > > Then you can easily access the public items on Form1 from Form2.
> > >
> > > JD.
> > >
> > > "Quest" <(E-Mail Removed)> wrote in message
> > > news:Uszeb.831$(E-Mail Removed)...
> > > > Ok. But the point is this : When you run the application, you are

> > viewing
> > > > the instance of the form that you created at design time. The

question
> > is,
> > > > how do you access this SAME instance in code ??
> > > > If I can access the same instance of the form in code, then I can

> access
> > > the
> > > > texbox1 on form1 that the user first sees when the application is

run.
> > > >
> > > > "Kumar" <(E-Mail Removed)> wrote in message
> > > > news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > > > > If you open the code for Form1, it may look like the
> > > > > following:
> > > > >
> > > > > Public Class Form1
> > > > > Inherits System.Windows.Forms.Form
> > > > > ....
> > > > > ...
> > > > >
> > > > > Which means that the form you see on the designer is
> > > > > nothing by an instance of the Form1 class. Visual Studio
> > > > > does a special job for you to show the form in design
> > > > > time. If you want refer any form you need to create an
> > > > > instance of it.
> > > > >
> > > > > I hope this helps.
> > > > >
> > > > > -Kumar
> > > > >
> > > > > >-----Original Message-----
> > > > > >Hi,
> > > > > >
> > > > > >I would appreciate any input on this problem. (Visual
> > > > > Basic.NET Windows
> > > > > >Application)
> > > > > >
> > > > > >Facts:
> > > > > >
> > > > > >I have created a new windows project from Visual
> > > > > Studio.net called 'Database2'.
> > > >
> > > > > >On the default created form called Form1 I have created a
> > > > > textbox called TextBox1 (at design time)
> > > >
> > > > > >I have created from Solution Explorer a new Module called
> > > > > Module1 and a new
> > > > > >form called Form2. (at design time)
> > > > > >
> > > > > >Problem:
> > > > > >
> > > > > >How do I access Textbox1 residing on Form1 FROM either
> > > > > Form2 or Module1. It
> > > > > >must however, reference the ORIGINAL instance of the form
> > > > > created at design
> > > > > >time (not a new instance).
> > > > > >
> > > > > >I have tried the following (both give an error message)
> > > > > code on Form2 :
> > > > > >
> > > > > >Database2.form1.Textbox1.text="test"
> > > > > >Form1.Textbox1.text="test"
> > > > > >
> > > > > >I can refer to a new instance of the form1 with the
> > > > > following code
> > > > > >
> > > > > >Dim myform as new Form1
> > > >
> > > > > >But then it would NOT be referring to the ORGINAL
> > > > > instance of the form.
> > > > > >
> > > > > >Any ideas on how to access the Textbox1 on Form1 created
> > > > > at design time without instantiating a new instance of Form1?
> > > > > >
> > > > > >Thank you.
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Quest
Guest
Posts: n/a
 
      10-01-2003
Yes it does work !!!
Thank you.

Lesson to be learnt here is that you can pass the instance of the Form1 as a
parameter, in this case we have used MyForm(this) or in VB.NET it is
MyForm(Me). Great.
Once again thank you for the insight.

"Jim Parker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You wrote:
> > Public Property myForm() As Form1
> > Get
> >
> > myForm = Form1
> >
> > End Get

>
> No, that won't work.
> Keep in mind that this blows in the face of good OO practices...
> Here is a crude example in C#; in VB.Net it would be very similar.
>
> In Form1, the form that is already instantiated:
>
> private Form2 frmTest;
> private void button1_Click(object sender, System.EventArgs e)
> {
> frmTest = new Form2();
> frmTest.MyForm(this);
> frmTest.Show();
> }
>
> In Form2, which is instantiated from Form1:
>
> private Form1 frmMyForm;
> public void MyForm(Form1 frmIn)
> {
> frmMyForm = frmIn;
> }
>
> Then in the instance of Form2 you can access anything declared as public

in
> Form1 by accessing it as frmMyForm.
>
> JD.
>
>
>
> "Quest" <(E-Mail Removed)> wrote in message
> news:kYBeb.1149$(E-Mail Removed)...
> > Thank you.
> > I think you have the right idea. With reference to your quote where you

> say
> > "Create a property of type Form1 on Form2, and set it to the already

> created
> > instance of Form1 ....", My question still stands as to how you access

> that
> > instance of Form1 in code ?
> > Remember, that Form1 is a 'type' and not an instance. Therefore we are
> > trying to access the instance of form1 that is automatically created by

VB
> > at runtime that is based on our design time creation of Form1.
> >
> > In form2, I have added the following code :
> >
> > Public Property myForm() As Form1
> > Get
> >
> > myForm = Form1
> >
> > End Get
> >
> > Set(ByVal Value As Form1)
> >
> > End Set
> >
> > End Property
> >
> > This gives an error message that Form1 is a type ! How do I access the
> > instance of Form1 from Form2 ?
> >
> >
> >
> >
> > "Jim Parker" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > The controls on forms are no longer public as they were in VB6.
> > > Create public properties on Form1 to share the info that is desired to

> > share
> > > (textBox1.Text, whatever).
> > > Create a property of type Form1 on Form2, and set it to the already

> > created
> > > instance of Form1 when an instance of Form2 is created.
> > > Then you can easily access the public items on Form1 from Form2.
> > >
> > > JD.
> > >
> > > "Quest" <(E-Mail Removed)> wrote in message
> > > news:Uszeb.831$(E-Mail Removed)...
> > > > Ok. But the point is this : When you run the application, you are

> > viewing
> > > > the instance of the form that you created at design time. The

question
> > is,
> > > > how do you access this SAME instance in code ??
> > > > If I can access the same instance of the form in code, then I can

> access
> > > the
> > > > texbox1 on form1 that the user first sees when the application is

run.
> > > >
> > > > "Kumar" <(E-Mail Removed)> wrote in message
> > > > news:131f01c3878f$c05f25c0$(E-Mail Removed)...
> > > > > If you open the code for Form1, it may look like the
> > > > > following:
> > > > >
> > > > > Public Class Form1
> > > > > Inherits System.Windows.Forms.Form
> > > > > ....
> > > > > ...
> > > > >
> > > > > Which means that the form you see on the designer is
> > > > > nothing by an instance of the Form1 class. Visual Studio
> > > > > does a special job for you to show the form in design
> > > > > time. If you want refer any form you need to create an
> > > > > instance of it.
> > > > >
> > > > > I hope this helps.
> > > > >
> > > > > -Kumar
> > > > >
> > > > > >-----Original Message-----
> > > > > >Hi,
> > > > > >
> > > > > >I would appreciate any input on this problem. (Visual
> > > > > Basic.NET Windows
> > > > > >Application)
> > > > > >
> > > > > >Facts:
> > > > > >
> > > > > >I have created a new windows project from Visual
> > > > > Studio.net called 'Database2'.
> > > >
> > > > > >On the default created form called Form1 I have created a
> > > > > textbox called TextBox1 (at design time)
> > > >
> > > > > >I have created from Solution Explorer a new Module called
> > > > > Module1 and a new
> > > > > >form called Form2. (at design time)
> > > > > >
> > > > > >Problem:
> > > > > >
> > > > > >How do I access Textbox1 residing on Form1 FROM either
> > > > > Form2 or Module1. It
> > > > > >must however, reference the ORIGINAL instance of the form
> > > > > created at design
> > > > > >time (not a new instance).
> > > > > >
> > > > > >I have tried the following (both give an error message)
> > > > > code on Form2 :
> > > > > >
> > > > > >Database2.form1.Textbox1.text="test"
> > > > > >Form1.Textbox1.text="test"
> > > > > >
> > > > > >I can refer to a new instance of the form1 with the
> > > > > following code
> > > > > >
> > > > > >Dim myform as new Form1
> > > >
> > > > > >But then it would NOT be referring to the ORGINAL
> > > > > instance of the form.
> > > > > >
> > > > > >Any ideas on how to access the Textbox1 on Form1 created
> > > > > at design time without instantiating a new instance of Form1?
> > > > > >
> > > > > >Thank you.
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forms authentication -- expired forms cookie vs. not provided forms cookie Eric ASP .Net Security 2 01-27-2006 10:09 PM
Forms authentication - Multiple login forms based on directory acc Keltex ASP .Net Security 1 01-24-2006 03:06 PM
Multiple forms without multiple windows doug Java 6 01-27-2004 04:20 PM
Multiple forms and Multiple submit buttons and validation sandyde2 Javascript 2 10-02-2003 09:25 AM
Web Forms VS Windows Forms Brendan Miller ASP .Net 2 08-11-2003 09:05 PM



Advertisments