multiple-Form Application.

J

JAPSTER

I need to synchronize the contents of 2 textboxes that are on
different forms.
When I change the contents of the textbox on Form1, the contents of
the textbox on Form2 should be changed to show the same contents as
that of the textbox on Form1, and vice-versa.

Form1 is the startup form for the application, in which I add:

Dim frm2 as new Form2

then in Form1_Load event:

frm2.Show().

in Form1 textbox1_textchanged event:

frm2.Textbox1.Text = Textbox1.Text.

That is all fine.

Then Textbox1_TextChanged event in frm2 I add:

form1.textbox1.text = textbox1.text.

This last line of code is my problem. It seems to me that Form1, the
started form, instantiated by VB on startup, is not available to my
frm2.

I really there must be a simple explanation, but as I am new to
vb.net, it's done me.

Help appreciated.
 
C

Cor Ligthert

Japster,

There are more roads which goes to Rome, however here a sample I did made
now for it.

\\\Form1 has one label
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm As New Form2
frm.Owner = Me
frm.Show()
End Sub
///
\\\form2 has one textbox
Private Sub TextBox1_TextChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles TextBox1.TextChanged
If Not Me.Owner Is Nothing Then
DirectCast(Me.Owner, Form1).Label1.Text = TextBox1.Text
End If
End Sub
////
I hope this helps?

Cor
 
W

whoopding

Thanks form the reply.

I tried this and it sorted out part of my problem. When text was
changed in form2, form1 was updated. But, unfortunately, when form1
was changed, form2 was not updated.

I am currently studying from a book called SAMS Teach Yourself Visual
Basic.net 2003 in 21 Days. This problem is an exercise in day four.
Prior to this exercise being set, there was a brief mention of a Forms
Collection. Although, since looking at VB.Net Documentation, it
appears that this collection is no longer supported. They can't both
be true!

VB.Net documentation recommends implementing your our own Forms
Collection. This seems to be a long winded way of solving what should
be a simple common problem.
Any more input would be appreciated.

Thanks.
 
C

Cor Ligthert

Whooping,

One of the wong things when you use OOP is making classes dependable from
each other.
(When they don't inherit from each other).

And in performance.
People make long messages in this newsgroups about boxing.

Painting in two forms at almost the same time cost definitly much more, so
try to avoid that.

Just my thought,

Cor
 

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