Help with forms

  • Thread starter Thread starter Wooten26
  • Start date Start date
W

Wooten26

Ok.. extremly new to NET so bear with me )

In VB5 you could do this

(in Form2)
form1.text1.text = "test"


now how do you change textbox propertys from another part
of code - like from a module or another form?

Thanks-
Noramn
 
First you need to make sure that text1's access modifier is set to public
(Public text1 As TextBox). After you do that, Form2 just needs to have a
reference to form1 somehow. There's a few different ways they could be
related.

If Form2 is a child of form1 (code goes in Form2):
Dim myForm1 As Form1 = Me.Parent
myForm1.TextBox1.Text = "Hi from form 2!"

If Form2 is owned by form1 (code goes in Form2):
Dim myForm1 As Form1 = Me.Owner
myForm1.TextBox1.Text = "Hi from form 2!"

You can create a property on Form2 like this:
Private _myForm As Form1

Public Property MyForm() As Form1
Get
MyForm = _myForm
End Get
Set(ByVal Value As Form1)
_myForm = Value
End Set
End Property

Then you just need to make sure you set that property before you try to
access it.

Good luck!
 
Wooten26 said:
Ok.. extremly new to NET so bear with me )

In VB5 you could do this

(in Form2)
form1.text1.text = "test"


now how do you change textbox propertys from another part
of code - like from a module or another form?

If you want to access an object, you need a reference. If you don't have
one, make it available, usually by passing the reference as a procedure
argument or to a property.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top