*/
Written some cool source code? Upload it to Programmer's Heaven.

Other Views

corner
*/

How to Access Controls on Another Form in VB.NET

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
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.