Solved

Accessing other forms

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

Technology Partners: 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

Title # Comments Views Activity
"Black Box" Testing of Control System Software 2 89
How to share My.Settings in multiple application instances ? 7 48
Why use this lambda? 12 60
Java List 4 32
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

685 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