Hi
frmTrigger still has no reference to frmMain because in frmMain you call the default constructor for frmTirgger. Look at this example below:
- public void Example()
-
{
-
-
}
-
-
public void Example(string name)
-
{
-
-
}
The above functions both have the same name, but different parameters, the first function accepts 0 arguments (like a default constructor) while the second function accepts one argument.
Example(string name) can thus have a value passed to it and you can reference that value within the function.
You always call
frmTrigger formtrigger = new frmTrigger(); see there is no parameter in this constructor, thus the code it calls is:
-
in frmTrigger Class
-
-
public frmTrigger()
-
{
-
InitializeComponent();
-
}
In the above constructor, there is no reference to frmMain, so you never execute
_frm1 = frm1; thus _frm1 is always null and your if statement will always return false.
To assign a value to _frm1 we must call the
public frmTrigger(frmMain frm1) constructor,
Remember that overloaded functions (functions with the same name but different arguments) are different sections of code that behave in a unique manner.
Without passing a reference to frmMain, frmTrigger cannot access it. In this scenario frmMain is just like a variable that must be passed from one function to another.
I hope this clarifies what is actually going wrong here. If you are new to development, i suggest you really try this until you understand what is happening as passing parameters is a common and very good programming technique.