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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple VB.NET control question 1

Status
Not open for further replies.

mookie0001

Technical User
Jun 14, 2002
23
US
Hi everyone,

I know that there is probably a very easy way to do this, but I have yet to figure it out. Here is the basic scenario:

Form1 contains Label1
Form1 creates an instance of Form2

Form2 contains Button1
Form2.Button1.onClick needs to set Form1.Label1.Text = "something" (without creating a new instance of Form1 because I need to keep all other values as-is).

Your help is appreciated. Thanks!

-Chris
 

are you closing Form2 on Click of Button1 as well???

Email: pankajmsm@yahoo.com
 
No, here is a sample from the code I am using:

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim form2 As New Form2()
form2.Show()
End Sub
End Class


Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Label1.caption = "something" ' this does not work
End Sub
End Class
 

first of all there is no Caption property for Label contorl. It should be Text

Secondly you have to instantiate Form1

Email: pankajmsm@yahoo.com
 
This isn't my actual code, I just posted psuedo code so that you could get the basic idea of what is going on...
 
I found the solution to my problem. In case anyone is interested:

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim f2 As New Form2()
f2.Create(Me)
End Sub
End Class


Public Class Form2
Private m_fParent As Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
m_fParent.Label1.Text = "something"
End Sub


Sub Create(ByVal fParent As Form1)
m_fParent = fParent
Me.Show()
End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top