Passing information between classes and forms

  • Thread starter Thread starter shawrie
  • Start date Start date
S

shawrie

hopefully my last post for a while im currently passing a couple of
variables between a number of forms. Im currently doing this my using
the private sub new and overiding it. Is this ok or is there a better
way of passing information between forms and classes
 
This is OK if you plan on passing all the data when you construct the
form/class instance. Otherwise, you can create properties with
getters/setters so that you can modify the data within the form/class after
instantiating it.

--
Neil Cowburn
Principal Partner
OpenNETCF Consulting, LLC.

http://www.opennetcf.com/
 
In the .NET world, a form is class. Therefore, you can do everything you do
with classes with forms too, including creating properties.
For example:

Imports System.Windows.Forms

Class MyForm
Inhertits Form

Dim m_someImportantData As String

Public Property SomeImportantData() As String
Get
Return m_someImportantData
End Get
Set(ByVal Value As String)
m_someImportantData = Value
End Set
End Property

End Class ' MyForm

Now you can pass data to MyForm by setting the MyForm.SomeImportantData
property like this:

Dim myFormInstance As New MyForm()
myFormInstance.SomeImportantData = "This data is really, really, REALLY
important. So there."

--Neil

--
Neil Cowburn
Principal Partner
OpenNETCF Consulting, LLC.

http://www.opennetcf.com/
 
Back
Top