How do I access controls on another Form?
To access controls on other WinForms follow the example. This example reads the text in a textbox from other form and displays it in the textbox on the current form.
Open two forms (form1 and form2), add a Command Button and a Textbox to Form1 and a Textbox to Form2.
The following code relates to form1.
Public Class Form1
Inherits System.Windows.Forms.Form
Dim NewWindow As New Form2()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NewWindow.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = NewWindow.TextBox1.Text
End Sub
End Class
When you run the code, Both Form1 and Form2 are displayed.
Enter some text in the Textbox on Form2 and click the button on form1.
The text entered in the Textbox in Form2 will be displayed in the Textbox in Form1.
Written by Sandeep Mogulla, Webmaster at
www.startvbdotnet.com
Index