How to communicate between forms

How do you communicate between forms in VB.NET? In VB 6 I am used to typing for example frmMySecondForm.property. How is this accomplished in VB.NET?
pcavinessAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
carlossConnect With a Mentor Commented:
Because as AzraSound mentioned above, a form is just another object.  You can create public methods on the form that can be called from other sections in your code as you would any other method of an object.  Such as

Form1:

Public Sub LockTextBox()

TextBox1.Locked = True

End Sub

Any other place in code:

Form1.LockTextBox

You can also define a public object and set its instance equal to the element you want such as:

Form1:

Public MyTextBox as TextBox

Public Sub Form1_OnLoad()

Set MyTextBox = TextBox1

End Sub

Any other place in code:

Form1.MyTextBox.Text = "Set from somewhere else"
0
 
AzraSoundCommented:
You should create instances of the forms using variables, since they are, after all, just classes that should be instantiated that way anyways, e.g.,


Dim f As frmMySecondForm = New frmMySecondForm()
f.Show()
0
 
pcavinessAuthor Commented:
I know about creating new instances of the forms but I want to be able to change elements on existing forms from other forms. Any suggestions?
0
 
pcavinessAuthor Commented:
I had to figure out a few things to get it to work such as making the objects shared. But it worked. Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.