• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Share controls between classes

I have a form in vb.net and want to include some classes outside the form class to perform some functions.  Is it possible to use the controls on the form, say a textbox, in the separate class without having to duplicate the value prior to calling the class function?  How do you address the controls directly  from a different class?
0
ddepuemd
Asked:
ddepuemd
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You would either pass a REFERENCE to the Form or the actual Control INTO your class and store their internally for use...
0
 
ddepuemdAuthor Commented:
Here's what I have done - I had a sub that examined several controls for legal values then wrote out a record to a database to save it.  I copied the sub to a new class and simply referenced the controls to the form as:

Form1.TextBox

This seems to work fine!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ok...that works because Form1 is the "Startup Object" for your application and you are actually accessing the "default instance" of the form (created for you when the app started).  If you were not dealing with the default instance the a REFERENCE to the desired form would have to be passed into your Sub....
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now