Solved

Accessing other forms

Posted on 2004-04-29
3
195 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
Comment Utility
   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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
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.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

12 Experts available now in Live!

Get 1:1 Help Now