Variable

  • Thread starter Thread starter mgalesic
  • Start date Start date
mgalesic said:
How could I access variable in Form2 declared in Form1.

What you need in 'Form2' is a reference to your instance of 'Form1'. You
can pass the reference to 'Form1' in a property when showing 'Form2' from
'Form1':

Code for 'Form1':

\\\
Dim f As New Form2()
f.Form1 = Me
f.Show()
///

Code for 'Form2':

\\\
Private m_Form1 As Form1

Public Property Form1() As Form1
Get
Return m_Form1
End Get
Set(ByVal Value As Form1)
m_Form1 = Value
End Set
End Property
///

You can access 'Form1''s properties inside 'Form2' with 'Me.Form1', for
example, 'Me.Form1.Button1.Text = "Bla"'.

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>
 
Back
Top