c# - Accessing one from another form, is it because it is a reference? -
i have tabcontrol in form 1 named tbcontrol. when press button example, change index of tabcontrol :
this.tbcontrol.selectedindex = 2;
it works.
then have form 2, in have done :
form1 form1 = new form1();
then try example :
form1.tbcontrol.selectedindex=1;
but doesn't work, tabcontrol doesn't change index. can tell me why ?
you changing selectedindex
on unshown new form1
. want change selectedindex
on existing form1
, you'll need find way pass other form. psuedo-code:
class form1 { private void onshowform2() { form2 f2 = new form2(); f2.mainform = this; f2.show(); } } class form2 { public form1 mainform { get; set; } private void dostuff() { //change selected index on passed in instance of form1 mainform.tbcontrol.selectedindex=1; } }
Comments
Post a Comment