Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie: How to reference control on a form

Status
Not open for further replies.

nigz

Programmer
Jun 15, 2001
60
GB
Hi - how on earth do you reference a control on one form from another? in vb6 it was for instance:

frmMyForm.MyControl.Text="Whatever"

how do you do it in .NET? many thanks
 
You need to think of it in terms of classes. In .Net, each form is a class. So if it is not instantiated, then you cannot access it.

For example, to reference an object on "Form2", do it like this:

Dim f2 as new Form2
f2.txt1.Text = "Text here."

 
I have tried that, here is my code, why cant I see tvwMain?
Many thanks.

Private Sub mnuFileNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
Dim frmNew As Form
Dim strProjectName As String

frmNew = New frmBuilder()
strProjectName = InputBox("Please enter new Project Name:")

If strProjectName <> &quot;&quot; Then

frmNew.MdiParent = Me
frmNew.Text = &quot;New Project&quot;
frmNew.tvwMain.nodes.add(strProjectName) 'this control is not recognised
frmNew.Show()

Else
frmNew.Close()
frmNew.Dispose()
frmNew = Nothing
Beep()
End If

End Sub
 
Ah - I've got it:

dim frmNew as frmBuilder
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top