By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

calling a function in another form

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Geoff Jones" <no********@email.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
Thanks for the prompt reply Herfried.

Could you give an example of this technique?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
As Mr Burns from the Simpsons would say...."Excellent"!!!

Thanks a lot Herfried

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a
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" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
As Mr Burns from the Simpsons would say...."Excellent"!!!

Thanks a lot Herfried

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #6

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

P: n/a
Interesting. Thanks again Herfried.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O$**************@TK2MSFTNGP12.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.