Controlling one form from another form

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

In VB 6.0 I could control the properties of one form by
writing code in another form, something like this:

In the code of Form2 I would write Form1.Visible=True.

How can I do this in VB. NET?
 
In VB 6.0 I could control the properties of one form by
writing code in another form, something like this:

In the code of Form2 I would write Form1.Visible=True.

How can I do this in VB. NET?

The second form needs to know about the instance of the original form.
Therefore create a Public Variable/Property of type of your original
form on the second form:

<code>
[Form1]
Private Sub SomeEvent(sender As Object, e As EventArgs)

Dim secondForm As New Form2
secondForm.OtherForm = Me
secondForm.Show

End Sub

[Form2]
Public OtherForm As Form

Private Sub SomeEvent(sender As Object, e As EventArgs)
'Do what you want eith OtherForm properties
OtherForm.BackColor = Color.Blue
End Sub
</code>

Hope this helps

Blu
 
Back
Top