Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Forms in different dlls needs to communicate
 

Forms in different dlls needs to communicate

hi,

I am fairly new to Visual Studio (2005, c++) and I havea large application that needs to be ported to this plattform. Most of the application we need to rewrite from scratch (as itcontains very bad code).

But since this application is large, I need to devide it into several dlls (assemblies) and I also need to put forms in the dlls.

I have tried to search the Internet for this, but I can't find out how the forms can communicate with eachother!

Do you understand my problem?

Well,

I have three dlls; A,B and C. In each dll I have one form AF, BF and CF.

AF is a mdiparent and BF and CF are childs. This works and I can show them and operate with them, but I cant get BF and CF to send data to eachother. I tried to use BF->MDIParent->CF, but I cant get BF to recognice MDIParent (which is AF), neither can in contact CF directly.

I have tried other forums but none could help me, so please.... You are my only hope!

Fisherking  Monday, August 14, 2006 10:08 AM

Hello,

By your description, all the forms are in the same process and there is one MDI Parent with several different children forms. Being in different DLL's doesn't make any real problems as long as everything is in the same process. If not then you have an entirely different problem. First thing to understand is that the way I see it by your description, there isn't a specific technology you are looking for, just different methodologies.

With that said, there are a LOT of different ways to get them to communicate. One way is directly.

Put a method in AF that will tell CF something when BF says to. Then just use the MDIparent property of BF to call the method in the MDI Parent. You will have to cast the propterty to your MDI parent to see the method.

MyMDIParent myParent = this.MdiParent as MyMDIParent;

string strMsg = "Hell form CF";

myParent.TellCfSomething(strMsg);

Then when BF calls the method, the Parent will tell cf the message. You could put a method in the MDI Parent to get a reference to CF and then just tell CF directly. You could loop through the children of the MDI Parent until you found CF or the form you are looking for. See what I mean by different ways?

Another way to do it, and probably how I would do it depending on your situation is use events.

Still talking about BF trying to talk to CF ok.

Put an event in BF that you can fire to get the data to CF. Then when the MDI Parent creates CF it creates a reference to the event in BF, and could assign the event handler to a method direclty in CF. Then when BF fires the event, CF receives it directly.

Did this help at all?

Ken

Ken_Bussell  Monday, August 14, 2006 5:03 PM

Thanks for the answer!

Bt I must say that my problem is a little bit more basic than this. What I am trying to do is this:

MyMDIParent myParent = this.MdiParent as MyMDIParent;

But BF above does not recognice MyMDIParent! That is basiclly the problem. I will try a couple of solutions ( that probably doesn't work ) and get back to you.

hmmm.. but I must say that the "event solution"is much nicer than the one I was going to use (with reference in BF to CF). thanks!

Fisherking  Wednesday, August 16, 2006 6:18 AM

The problem I have is that if Icannot add the A project to the B project because ofcircularity

Fisherking  Wednesday, August 16, 2006 8:35 AM
i suggest you try to reorganize your projects/assemblies properly. Ideally, these forms should be in a single dll/project so you prevent those nasty circular dependencies.
joeycalisay  Wednesday, August 16, 2006 9:49 AM

joeycalisay wrote:
i suggest you try to reorganize your projects/assemblies properly. Ideally, these forms should be in a single dll/project so you prevent those nasty circular dependencies.

Yes, this would be ideally, but this project contains a large numbers of forms so that is not an option! Is there another solution?

Fisherking  Wednesday, August 16, 2006 11:01 AM
you can try working around interfaces if you want for your setup

AF ->CF
AF -> BF

your mdiparent assembly will reference your childforms since it will be the controller. CF should ideally not know of its MDIParent custom methods so you can try creating an assembly containing an interface which your MDIParent form should implement (this assembly should be the topmost where mdiparent assembly and mdichild form will reference). so if ever you want to invoke a method (defined in the interface of your mdiparent), you cast it to the said interface first before invoking it

public interface IMyMDIParent
{
public void ShowBFForm();
}


so from a childform, you'll do

((IMyMDIParent)this.MDIParent ).ShowBFForm();

pretty messy, good luck!
joeycalisay  Wednesday, August 16, 2006 12:10 PM

You can use google to search for other answers

Custom Search

More Threads

• Preventing Undo Actions
• IsInputKey
• Creating Custom Controls
• Can a component know where it is? on initialize?
• Is there anyway to set the width of a textbox according to its maxlength property???
• I need the list control (styled with check boxes) to move its focus and selects the list item that I just checked.
• adding a listviewgroup programmically
• SplitContainer-Type compound controls
• Drag drop in VC++.net
• There is already a command handler for the menu command '5efc7975-14bc-11cf-9b2b-00aa00573819 : 17'