This is the property definition:
Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
And from the other form I call frmMain.TextboxWTN = "Whatever"
It has no effect over the form's textbox.
Thanks
-----Original Message-----
From: Jack Jackson [mailto:
[email protected]]
Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them
It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.
The second piece of code creates a new instance of your form, not
something that you want to do.
By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?
What does the property definition in form1 look like?
Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue
or
Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.
Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:
[email protected]]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them
Hi,
I have a form with some controls, and a different class that needs to
modify some control properties at run time.
Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
Regards,
Mike
My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.
For example, if you want a second form to be able to modify a label's
text property expose it like this:
////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////
If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.
Thanks,
Seth Rowe