Passing values between three forms in C# .NET -


i have windows application has 3 forms : form1,2,3.

--form 1, has 2 buttons , openform2, openform3. --form2 has textbox form2_textbox,and button form2_button --form3 has textbox form3_textbox

now, on clicking button openform2 on form1, form2 opens, string entered in textbox form2_textbox of form2, when bu tton form2_button of form clicked, want form1 receives string value & stores in string receivefromform2, , displays string value on form3_textbox of form3.

please guide me how task?

there couple of ways this. using .net events 1 requires pretty coupled wiring.

what suggest (and how this) use own bus (observer pattern). let's call messagebus. forms use same instance of bus , when interesting happens publish message. keep typed sake of simplicity let's this:

public class message<t>  {      public string name { get; set; }     public t data { get; set; } } 

you have subscribers on bus respond messages interested in.

public class messagebus {     public void subscriber(isubscriber subsriber)     {          // register subscriber in list     }      public void publish(message message)     {          // loop through subscribers , let them know          // e.g. subscriber.handle(message);     } } 

so wire each form publish event (such form2) need reference message bus , each object interested in receiving events (such form3) register subscriber.

the difference between using .net events various publishers , subscribers not need know each other loosely coupled --- need know bus. possible same loose coupling using .net events takes lot of fancy footwork.

more 1 way skin cat suppose.

i have more mature implementation of in composite ui framework use tooling on our foss service bus. can take if interested:

shuttle service bus on codeplex

if download source find in shuttle.core.ui project.

hope makes sense.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -