You have pretty much answered this yourself:
Set up a property in the destination which accepts the string.
Then hand it over from the source to the destination instance.
public class MyForm
{
public string ValueFromDataBase { get; set; };
}
...
MyForm myNewForm = new MyForm();
myNewForm.ValueFromDataBase = "hello there";
myNewForm.Show();
What is giving you difficulties?
"i will close form1 but when i access it on another myNewForm it find null?"
Yes: they are separate instances, just as two different strings are:
string first = "First string";
string second = "Second String";
You would not expect them to contain the same text, would you?
MyForm myNewForm = new MyForm();
myNewForm.ValueFromDataBase = "hello there";
myNewForm.Show();
MyForm myNewForm2 = new MyForm();
myNewForm2.ValueFromDataBase = "hello there";
myNewForm2.Show();
Equally you would expect the two instances of the form to have separate ValueFromDataBase values!
If all instances of a form (or any other class) must access the same string (i.e. they will all use the same database and you want to pass the connection string to them all) then you can declare the property as
static
:
public class MyForm
{
public static string ValueFromDataBase { get; set; };
}
And then you only set it once for all instances of MyForm. Be carefull though: only use this when the value will allways be the same for all instances - any even then, think about why you need that. Overuse of
static
variable is a bad idea - it makes things difficult to change.