@JohnH, is likely correct because
Friend
is the default access level for fields when you add a control or component in the designer. There are two solutions: a good one and a bad one.
The bad one is the easier option so it is very tempting. That is to simply change the access level of the control from
Friend
to
Public
in the designer. If you do that, you code will work.
The problem with that is that setting the
Text
of the control is not the only thing you can then do. You can access every member of the
TextBox
, e.g.
Size
,
Location
and
Dispose
, and you can also replace the
TextBox
itself with a different one. That's all bad. You should not be able to do anything that you don't need to do from outside a class for that reason, you should use the good solution.
What you should do is actually make the control - ALL controls and components -
Private
and then provide pass-through members for only the functionality you specifically need outside the form. I call them "pass-through" members because they are like little holes in the object that you can pass data through. In this case, you only need to access the
Text
property so that's the only one you should allow to pass through. You would do this is the form:
Public Property TBEditBoxDepthText
Get
Return TBEditBoxDepth.Text
End Get
Set
TBEditBoxDepth.Text = value
End Set
End Property
and then you would change your existing code to this:
Dim ex As New FEditDox
ex.TBEditBoxDepthText = "200"