VB.NET Beginner question

  • Thread starter Thread starter aXiS_PoWeR
  • Start date Start date
A

aXiS_PoWeR

Guest
how do you control objects on one form from another? in VB6 it was as simple as formname.textbox.text="blah"...now since they took out the simple things in life i cant figure out a way to do that...can anyone tell me how?
 
Ill assume you are calling one form (frmPopup) from your main form (frmMain). You should be calling this form as follows:


Dim Popup As New frmPopup()
Popup.Show()


You can then reference obects on that form. For example, say you have an label called "lblChangeMe" then you can change the text property with code as follows:


Popup.lblChangeMe.Text = "This text was changed by frmMain"


Hope this helps!
M.
 
I suspect hes trying to access stuff on frmMain from frmPopup. If hed have searched this forum hed have found this question is asked in various forms at least once a week.

My preferred solution is to alter the constructor of the secondary form so it takes a reference to the first form as a parameter, which can be stored for whenever you need to access it.

You could also set the tag of the secondary form to reference the first form after creating it, but that would mean you wouldnt be able to reference frmMain from the constructor.
 
i did the constructor n everything but still from form2 i can only get properties of form1 and not the controls on it...
 
Then youre declaring it wrong. Declare it as frmMain, not Form. Or cast it when necessary.
 
Back
Top