vb.net - referencing form button from another form -


i have 2 forms both same buttons on, , want have if click button both buttons same thing i.e. referencing each other on different forms. way found was:

public class form2  dim form1 new form1   private sub button2_click    form1.backcolor=black    form2.backcolor=black  end sub end class 

then

public class form1  dim form2 new form2   private sub button1_click    form1.backcolor=black    form2.backcolor=black  end sub end class 

only doesn't work there error:an unhandled exception of type 'system.stackoverflowexception' occurred in system.windows.forms.dll far can see there no infinite loop or stack on flow. appreciated.

you have infinite loop, because each time 1 of forms instantiated, instantiating other. creating form1 create form2, form2 creates form1 , on , on...

change code this:

public class form2    private sub button2_click        dim form1 new form1        form1.backcolor=black        form2.backcolor=black    end sub end class  public class form1     private sub button1_click         form1.backcolor=black         dim form2 new form2         form2.backcolor=black     end sub end class 

now create other class instances when click button.


Comments