When you create a new form:
if (String.IsNullOrEmpty(Form2 frm = new Form2(label1.Text)))
Form2 frm = new Form2(label1.Text) = '1'.ToString();
Or
else if (Form2 frm = new Form2(label1.Text).contains(int))
Or
int i = Form2 frm = new Form2(label1.Text);
You do just that: create a brand spanking new form that has nothing at all to do with any existing version. And because of scope rules it never could as it is no longer available after teh following close curly bracket.
So this code:
if (String.IsNullOrEmpty(Form2 frm = new Form2(label1.Text)))
{
Form2 frm = new Form2(label1.Text) = '1'.ToString();
}
does nothing useful at all!
You create a new form in your
if
condition, which will always have the default value youset in teh designer. So if that's an empty string the test will always pass, regardless of what your label contains on any visible form.
That is then "thrown away".
You then create another new form and ... well, it won't compile, so it doesn't matter what it does really - create a character, convert it to a string, assign it to new form (assuming there is a constructor that accepts a string parameter, and that
label1
exists in the current class / form, and then try to assign that to a Form2 variable before it all goes out of scope and is thrown away?
You need to stop guessing what you are doing, and start thinking. "Hope and pray" is not a viable coding strategy!
As Chill has said, communicating between forms isn't that difficult, the full list of my tips on the subject is here:
The form that creates an instance of another:
MyForm mf = new MyForm();
mf.Show();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)
Transferring information between two forms, Part 1: Parent to Child[
^]
Transferring information between two forms, Part 2: Child to Parent[
^]
Transferring information between two forms, Part 3: Child to Child[
^]
But tio be brutally honest, on the basis of your code sample you aren't ready for that yet - you have a lot to learn before you get to creating and handling events!