forms and classes

eagle

Active member
Joined
Mar 8, 2005
Messages
28
Programming Experience
1-3
Hello,

this is maybe a bit of a stupid question, but i just need to be sure of this. Is it possible to change properties of a control on a form from a class file?
So i have form with a text box. Then i make a class file and in that class file i want to change the text property of the text box on my other form. Is that possible?

Thanks
Eagle
 
as far as i know it's not possible to change it directly from the other class

but on the form you can have a sub that's got the scope of Friend that you can call from the other class that will change the property such as:

VB.NET:
'On form:
Friend Sub ChangeTextBox (byval Text as String)
  Textbox1.Text = Text
End Sub

'Other class file:
Call Form1.ChangeTextBox("This is the new text")
 
When you add a control to a form the default scope of the control is Friend. Personally, I always change it to Private and then either add a property or method, as JuggaloBrotha suggests, to alter properties of a member control. If, however, you leave the control as a Friend (or change it to Public), then you can access the text of a text box as Form1.TextBox1.Text. Of course, regardless of which method you use, you have to have a reference to the form instance to begin with.
 
Back
Top