problem with modeless dialog

P

proit_123

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.
 
C

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
 
C

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
 
G

Guest

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
 
B

Bruce Wood

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.
 
P

proit_123

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.ValueFromModelessDialog);)
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.
 
B

Bruce Wood

I will be fine with your code, but how can i get the reference of the
Main Form method(MainFormMethod(closingMd.ValueFromModelessDialog);)
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top