*
as**********@gmail.com (Ash) scripsit:
Ok, in VB6, if, for instance, I was in "frmAdd", I could use the code:
Dim X as ListItem
X = frmMain.lvwMain.ListItems.Add("blah")
VB .NET doesn't seem to allow me to access controls on the form (that I can see).
Let 'MainForm' be the class name of your app's main form. Add the code
below to your project, then go to the project settings and change the
startup object to 'Sub Main':
\\\
Public Module Program
Private m_MainForm As MainForm
Public ReadOnly Property MainForm() As MainForm
Get
Return m_MainForm
End Get
End Property
Public Sub Main()
m_MainForm = New MainForm()
Application.Run(m_MainForm)
End Sub
End Module
///
You can access the main form from everywhere in the app by typing
'Program.MainForm'.
- or -
\\\
Public Class Program
Private Shared m_MainForm As MainForm
Public Shared ReadOnly Property MainForm() As MainForm
Get
Return m_MainForm
End Get
End Property
Public Shared Sub Main()
m_MainForm = New MainForm()
Application.Run(m_MainForm)
End Sub
End Class
///
There are still some alternatives, for example, you can implement the
singleton design pattern for your forms in order to access them by their
class name.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>