c# - Fill Identity Of WinForms Into Textboxes -


i have 3 forms below:

form1

form2

form3

the form1 , form3 communicating form2. want if form1 visited form2

form1 should leave it’s identity form2’s textbox1. if form3 visited form2 form3

should leave it’s identity form2’s textbox2.

is possible?.

here visted means below.

by form1

form2 f2= new form2(); f2.show(); 

by form3

form2 f2= new form2(); f2.show(); 

and identity "form1" , "form3"

the best thing overload show method each of forms accept "previous form" parameter serve reference caller (you either form object, properties access, or string). then, wherever show second form existing form, pass information existing form show method second form. second form's show method take care of updating textbox name of form displayed it.

for example, each form contain overloaded show method:

public void show(form previousform) {     //set textbox on form contain name of calling form     mytextbox.text = previousform.name;      //call base class's method show form     base.show(); } 

and show 1 form calling overloaded show method:

private void showotherformbutton(object sender, eventargs e) {     //create new instance of form want display     form2 myotherform = new form2();      //show other form, passing calling form parameter     myotherform.show(this); } 

this way, no form responsible or allowed update controls contained form. don't have expose additional properties or remember call additional methods on forms want show—it's built right show method have call anyway.

alternatively, overload each form's constructor in same way, won't work if want able move between existing instances of each form. you'll able specify information previous form when you're creating new instance of each form.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -