Using Object in another Form [closed]

0

How can I use an object declared on my form 1 to use it on my form2. In my form 1 the user enters some data that is stored in an object declared in the form1.cs and I want to operate that object on my form 2. Thanks

    
asked by Yair P. 17.09.2018 в 01:22
source

1 answer

-1

You have 2 ways that occur to me at the moment, if you upload code I can help you better.

1_ STATIC VARIABLE = create a static variable in a class, or within your own form, so from whatever side you call it always has the last value you assigned, for example if you want to call it from FORM2 and that variable is within your FORM1 would be like this FORM1.staticVAR , simple, like any other class, but without instantiating it.

2_PASS IT BY PARAMETER = when creating your FORM2 from your FORM1 pass it by parameter in its constructor, example new FORM2 (VARIABLE) .show (); and from the constructor of your FORM2 you add that a variable is going to be passed, example:

private object obj;
public FORM2(object obj)
{
    this.obj = obj;
}

I hope you understand and help you, however, if you add code to your question, it is more likely that the question will be interpreted better. Greetings

    
answered by 17.09.2018 / 02:10
source