attach an event in one form to control in another form

I have two forms in the same project- form 1 and form 2. The user selects a button in form one which selects the openformdialog control. They select a media file. I want this media file to be played using the media controller in form 2. How do i make this reference in form 2 to the control in form 1?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Something like this:

Form1.MediaController1.File = "c:\movie.mpg"
Another way:

Put the event which handles Form2.Closing in Form1's code.  You must declare form2 "withevents" for this to work:

Public Class frmMain '<< your main form
    Inherits System.Windows.Forms.Form

    Dim WithEvents Form2 As New Form2 '<< declare your other form withevents

'== more code...

'This event is fired when Form2 is about to close
'This is your chance to grab all the info from the form.
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Form2.Closing
        'grab all the info from the form before it closes
    End Sub
sebastizAuthor Commented:

But i want form 2 to grab the information from form1 as it loads up (ie the media player in form1 will use the file that has been selected from the listbox in form1)

If you want form2 to grab the information from form1 as it loads up, one way is to modify the Sub New in Form2, pass the file name to Form2 as parameter:

    Private _file As String

    Public Sub New(ByVal file As String)

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call
        _file = file
    End Sub

When you open Form2 from Form1:
    Dim f As New Form2(fileName)
Another way is to add a public property in Form2:

    Private _fileName As String

    Public Property FileName() As String
            Return _fileName
        End Get
        Set(ByVal Value As String)
            _fileName = Value
        End Set
    End Property

When you open Form2 from Form1:
    Dim f As New Form2()
    f.FileName = fileNameFromForm1

In your Form2, you can use _fileName as the file to be played.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.