Circular link

I am looking for a good template to solve the following round link in a Windows Form application:

  • Assembly 1 contains a Windows form with an Infragistics menu item. Show form in assembly 2
  • Assembly 2 contains a Windows form with an Infragistics menu item. "Show" the form in assembly 1

In the general menu there are the same elements in the application. Thus, both in assembly 1 and in assembly 2 there are links to each other on the "New" forms of each other and. Show them.

Size note: My application is an existing application, so the situation is not as simple as the above situation with two assemblies. But if I can solve the above simply (perhaps without implementing a, I can apply this to a much larger application (about 20 components, all with several forms that appear with each other in components).

I have come up with a few solutions, but they all seem cumbersome. Is there a simple solution that I am missing?

+3
source share
5 answers

Use a factory component or component composer, such as MEF , to create instances without reference to the assembly of the component source.

+1
source

You can (in both cases) make the button just raise the event. The exe wrapper refers to both assemblies and joins the evens to show a different shape.

So exe knows about both; none of the forms knows about the other.

For example (same concept):

using System; using System.Windows.Forms; class Form1 : Form { public event EventHandler Foo; public Form1() { Button btn = new Button(); btn.Click += delegate { if(Foo!=null) Foo(this, EventArgs.Empty);}; Controls.Add(btn); } } class Form2 : Form { public event EventHandler Bar; public Form2() { Button btn = new Button(); btn.Click += delegate { if (Bar!= null) Bar(this, EventArgs.Empty); }; Controls.Add(btn); } } static class Program { [STAThread] static void Main() { ShowForm1(); Application.Run(); } static void ShowForm1() { Form1 f1 = new Form1(); f1.Foo += delegate { ShowForm2(); }; f1.Show(); } static void ShowForm2() { Form2 f2 = new Form2(); f2.Bar += delegate { ShowForm1(); }; f2.Show(); } } 
+4
source

Have you considered creating the third assembly and moving all the common code to the 3rd assembly?

+2
source

How about using interfaces? You can create a third library containing interfaces, and each window implements one interface from itself and refers to the interface of another window.

0
source

I decided at the moment to use reflection to pop up the windows that need to pop out. I remove the need to access them directly, and I can really add components more easily without creating all cross-references.

I looked at MEF, but unfortunately I'm using VS2003, not VS2008. This sentence started me on a path of simple reflection.

Thanks.

0
source

All Articles