3
Answers

Help in passing an object (button control Name) of one form to another form

Jay

Jay

19y
2.2k
1
I am new in programming application using .Net CF, so I would appreciate your help. Here is the scenario I have that I would need help in. I have forms with same namespace, I have form1 which has button1 in it, and I have form2 which has button2 in it. The scenario is when if i have form1 open and I press button1 it will open form3 , also in case i have form2 open and press button2 it will open form3. Till now everything looks simple....the problem that I am facing and trying to solve is the following: if form3 is opened from form1 and I press buttonX on form3, form4 will open. if form3 is opened from form2 and I press buttonX on form3 , form5 will open. what I need to do is to pass an object(button Name) from either of the forms into form3 and based on that form3 will make the decision of which form to open next either form 4 or form5. at first i passed the string(Text) of button1 and button2 into a method used by form3, and made the decision based on that here is the code: class form1 button1_click { form3 f=new form3(); f.method1("button1 Text"); f.show(); } class form2 button2_click { form3 e=new form3(); e.method1("button2 Text"); e.show(); } class form3 public void method1(string txt) { string s; s=txt; } buttonX_Click(sender,eventargs) { if(s=="button1 Text") { form4 h=new form4(); h.show(); } else if(s=="button2 Text") { form5 h=new form5(); h.show(); } } this works fine if I am using only one language in my application but if i have multiple languages in my app then it would be a problem, this is why I need to pass something other than the string (text) of that button, maybe the object....if u know a solution to that problem please post ur reply...i am really stuck here.
Answers (3)