c# - calling a form from 2 different methods -


i am trying access form button sends on data, , menustrip button looks @ form, no data transferred.

to send data on have class name being:

    public xsecform(string datarecieved)     {         initializecomponent();          xsavedlist.text = datarecieved;     } 

this allows me send data on over first button.

ive seen other saying put

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

in menu button show window without data passing, because of (string datarecieved) @ end of form keeps giving me errors.

i hoping there may way without changing how data being sent over.

a couple of methods can try, each have benefits , drawbacks.

1) can have 2 constructors second form. 1 default (would not pass in data), , other allow pass in string.

public xsecform(string datareceived) {     initializecomponent();     xsavedlist.text = datareceived; }  public xsecform() {     initializecomponent(); } 

this way can make new instance of second form or without sending string in. drawback can pass in data when first create object.

2) make public property in second form allow first form inject data in itself. in second form:

public string savedlistdata {     set { xsavedlist.text = value; }     { return xsavedlist.text; } } 

then on main form (assuming have default constructor)

xsecform f2 = new xsecform(); f2.savedlistdata = "asdf"; f2.show(); 

the benefit approach can get/set data whenever, after have loaded , have used second form.