473,508 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling a function in another form

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
7 5995
"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
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
"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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2383
by: Satish Chimakurthi | last post by:
Hi all, My question is surely a basic one, but somehow, I am not able to figure it out. I have a python file "satish.py" as follows: *satish.py* def main(): y()
10
600
by: headware | last post by:
I know that you can call the method of one from from inside another form by doing something like this Forms("MyForm").MyFunction(12, 34) However, you have to know that MyForm has a function...
14
2980
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
6
17550
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
5
4614
by: mike | last post by:
If I have a document like: <script> function mike_test() {alert('hi');} </script> <iframe src="blank.html" id="my_iframe1"> </iframe> and in blank.html I have:
4
2223
by: Bugs | last post by:
Hi, I wonder if anyone can help me out. I'm building a vb.net application that has a form with a panel that contains several other sub forms (as a collection of controls). What I'm wanting to...
13
18657
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
1
1740
by: SAL | last post by:
Hello, I'm developing this remoting app (.net 2.0) and I need to bring the server app's form to the front often. Since you can not do cross-thread communication on a form or control without using...
10
6924
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.