469,315 Members | 1,600 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

problem with modeless dialog

I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

Can somebody please suggest a way to achieve this?
Thanks,
Sunil Kiran B.

Jul 27 '06 #1
8 5210
hi,
You could maybe use reflection to call the method in another process or
you could use a message system between the two ( i.e; MSMQ )

James Jenkins
http://www.tamarsolutions.co.uk
<pr*******@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

Can somebody please suggest a way to achieve this?
Thanks,
Sunil Kiran B.

Jul 27 '06 #2
cp
You should be able to attach a delegate to the modeless dialog and
create an event handler in your main form which will update the main
form when it closes.

cp

pr*******@hotmail.com wrote:
I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

Can somebody please suggest a way to achieve this?
Thanks,
Sunil Kiran B.
Jul 27 '06 #3
cp
Apologies ... that came out a bit wrong.
When you close your modeless dialog, you can call the delegate function
which will hook back into your main form.

cp

cp wrote:
You should be able to attach a delegate to the modeless dialog and
create an event handler in your main form which will update the main
form when it closes.

cp

pr*******@hotmail.com wrote:
I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

Can somebody please suggest a way to achieve this?
Thanks,
Sunil Kiran B.
Jul 27 '06 #4
You can pass a reference to an instance of (what you call) "Project A" into
the constructor of the other class and store it in a field of type "Project
A" in the called class. This provides your second "project" (class) instance
with a reference to the other class, and allows you to call methods on it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"pr*******@hotmail.com" wrote:
I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

Can somebody please suggest a way to achieve this?
Thanks,
Sunil Kiran B.

Jul 27 '06 #5

pr*******@hotmail.com wrote:
I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)
In your main form in project A:

ModelessDialog md = new ModelessDialog();
md.Closing += new CancelEventHandler(this.ModelessDialogClosing);
md.Show();

then:

private void ModelessDialogClosing(object sender, CancelEventArgs e)
{
ModelessDialog closingMd = (ModelessDialog)sender;
MainFormMethod(closingMd.ValueFromModelessDialog);
}

or something like that.

Jul 27 '06 #6
Hi Bruce,

Thanks for your response.

I will be fine with your code, but how can i get the reference of the
Main Form method(MainFormMethod(closingMd.ValueFromModelessD ialog);)
because there is no reference of Project A in Project B.
If i try to add the reference of Project A in Project B it wont allow
because it will be a cyclic reference.
Sunil Kiran B.

Bruce Wood wrote:
pr*******@hotmail.com wrote:
I am working on a windows forms application and have the following
requirement.

I have two projects in my application Project A and Project B. And
Project A has the reference of Project B. I need to display a modeless
dialog from the main form which is in Project A and the modeless dialog
to be raised is in Project B. After closing the modeless dialog i need
to pass a value from modeless dialog to the main form of Project A and
also i need to execute a method in the main form with that value.
(the problem is i can not able to create an object of the main form
because Project B has no reference of Project A)

In your main form in project A:

ModelessDialog md = new ModelessDialog();
md.Closing += new CancelEventHandler(this.ModelessDialogClosing);
md.Show();

then:

private void ModelessDialogClosing(object sender, CancelEventArgs e)
{
ModelessDialog closingMd = (ModelessDialog)sender;
MainFormMethod(closingMd.ValueFromModelessDialog);
}

or something like that.
Jul 28 '06 #7
pr*******@hotmail.com wrote:
I will be fine with your code, but how can i get the reference of the
Main Form method(MainFormMethod(closingMd.ValueFromModelessD ialog);)
because there is no reference of Project A in Project B.
If i try to add the reference of Project A in Project B it wont allow
because it will be a cyclic reference.
Sunil Kiran B.

In your main form in project A:

ModelessDialog md = new ModelessDialog();
md.Closing += new CancelEventHandler(this.ModelessDialogClosing);
md.Show();

then:

private void ModelessDialogClosing(object sender, CancelEventArgs e)
{
ModelessDialog closingMd = (ModelessDialog)sender;
MainFormMethod(closingMd.ValueFromModelessDialog);
}

or something like that.
All of the code I wrote should be in project A, in your main form
class. The modeless dialog will signal when it is closing via its
Closing event. Your main form will listen to that Closing event and run
*its own* ModelessDialogClosing method when that happens. There are no
changes / coding required in the modeless dialog itself.

Jul 28 '06 #8
Thanks Bruce. It is working fine.

SKB

Jul 29 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Carmine | last post: by
reply views Thread by Andrew | last post: by
1 post views Thread by Bruno van Dooren | last post: by
2 posts views Thread by proit_123 | last post: by
3 posts views Thread by AboutJAV | last post: by
reply views Thread by Sin Jeong-hun | last post: by
1 post views Thread by BillE | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.