Solved

How to communicate between forms

Posted on 2002-03-30
4
147 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:pcaviness
  • 2
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6907948
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
 

Author Comment

by:pcaviness
ID: 6908166
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
 

Accepted Solution

by:
carloss earned 75 total points
ID: 6908395
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
 

Author Comment

by:pcaviness
ID: 6909229
I had to figure out a few things to get it to work such as making the objects shared. But it worked. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now