Solved

Accessing other forms

Posted on 2004-04-29
3
211 Views
Last Modified: 2010-04-17
IN VB.Net, I'm looking for a simple means of being able to access controls on a form from code in another form.  In old VB this was as simple as accessing Form1.Label.Text, etc.  I know this isn't directly and automatically possible because of the of the nature of VB form classes/references/instances, but I was hoping someone would be able to show me an easy way to set it up so it works similar to old VB (or, at least, in an easy to use fashion ;)  Thanks!
0
Comment
Question by:instruo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10954764
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f As New Form2
        f.TextBox1.Text = "tada!"
        f.Show()
    End Sub

If you need access to your instance of Form2 outside of the button event then you need to declare f at the Form level.

Idle_Mind
0
 
LVL 3

Expert Comment

by:Phoenixric
ID: 10955481
There is a question posted here exactly the same as your's and definitely find the solution.

This is what your looking for :

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20716845.html

PhoenixRic :-)
0
 
LVL 1

Accepted Solution

by:
curt_henderson earned 50 total points
ID: 10981102
Here is the way to do it so that it is just like VB6

You have to declare your control as Public Shared...
Go to the Windows Form Designer generated code
Find the declaration for the control and change it from Friend to Public Shared

You should now be able to access your control from other forms.
Hope that helped.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

726 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