Solved

Share controls between classes

Posted on 2009-05-05
3
203 Views
Last Modified: 2012-05-06
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
Comment
Question by:ddepuemd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24308232
You would either pass a REFERENCE to the Form or the actual Control INTO your class and store their internally for use...
0
 

Author Comment

by:ddepuemd
ID: 24308743
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24308853
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question