calling a function in another form

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

Could somebody give me an example of a way to call another member function
of another form from a form that has been called using ShowDialog?

Thanks

Geoff
 
Geoff Jones said:
Could somebody give me an example of a way to call another member function
of another form from a form that has been called using ShowDialog?

Pass a reference to the form to your dialog before calling its 'ShowDialog'
method, for example, by assigning it to a property of the dialog.
 
Geoff Jones said:
Could you give an example of this technique?

In your dialog form:

\\\
Private m_ResultForm As MainForm

Public Property ResultForm() As MainForm
Get
Return m_ResultForm
End Get
Set(ByVal Value As MainForm)
m_ResultForm = Value
End Set
End Property
..
..
..
Me.ResultForm.Label1.Text = "Hello World!"
///

In the main form:

\\\
Dim f As New DialogForm()
f.ResultForm = Me
f.ShowDialog()
f.Dispose()
///
 
Just as a matter of interest though, why doesn't this work:

'from within the dialog code
Me.Parent.funtionInCallingForm()

where funtionInCallingForm() is the function in the form where the dialog is
created. That is, as the parent of the dialog is that form, I thought this
might work - it doesn't :(

Can anybody explain why it doesn't work?

Geoff
 
Geoff Jones said:
Just as a matter of interest though, why doesn't this work:

'from within the dialog code
Me.Parent.funtionInCallingForm()

There is no parent-child relation between the form that shows the form and
the form that is shown modally.
 
Interesting. Thanks again Herfried.

Herfried K. Wagner said:
There is no parent-child relation between the form that shows the form and
the form that is shown modally.
 
Back
Top