Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,047 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,531 people online right now. Registration is fast and FREE... Join Now!




Forms: Accessing controls

 
Reply to this topicStart new topic

> Forms: Accessing controls, How do you access controls on different forms?

AdamSpeight2008
Group Icon



post 17 Jul, 2008 - 09:29 AM
Post #1


I've decided to write this tutorial to explain how to access controls on different form, a popular topic of discussion.
The basic format
Form.Control.Property
Name of Form. e.g. Form2
Name of Control. e.g. Label
Name of Property e.g. Text

Example
Start a new Windows Form Application.
To Form1
Add a textbox
Add a button
Add a label

Now add a new Form, to this form
Add a textbox
Add a button
Add a label

Double click on Form2 Button

vb

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Take the contents of the textbox on this form and put it the label on the other form
Form1.Label1.Text = Me.TextBox1.Text'
' Me.Textbox1 is used because VB.Net can't use name of the form of which this control is a part of.
End Sub


Now go back to Form1 double click on the button
vb

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Take the contents of the textbox on this form and put it the label on the other form
Form2.Label1.Text = Me.TextBox1.Text
' Me.Textbox1 is used because VB.Net can't use name of the form of which this control is a part of.
End Sub


Double click on Form1
vb

Form2.Show


This post has been edited by AdamSpeight2008: 19 Jul, 2008 - 08:32 AM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 12/1/08 05:14PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month