Solved

Accessing other forms

Posted on 2004-04-29
3
198 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
3 Comments
 
LVL 85

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

840 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