Solved

Accessing other forms

Posted on 2004-04-29
3
206 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

739 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