I have a main form called Form1 and a child for called Form2.
I put the code below in Form2's declaration as a reference to Form1.
private Form1 m_parent;
public Form2(Form1 frm1)
{
InitializeComponent();
m_parent = frm1;
}
My problem is I cant see any reference how Form1 can be tied to Form2.
As far as I know m_parent and frm1 are a type of Form1 in this code
but can this refer to Form1?
Any explanation would be appreciated.
Tamas
Loading
VulpesPosted Apr 18, 2013, 5:21 PM
The code to launch Form2 from Form1 would then be on these lines:
Form2 f2 = new Form2(this);
f2.Show();
So Form1 passes a reference to itself (i.e. this) to Form2's constructor and the latter stores it in a private field for later use.
Of course, the access modifier of the controls, methods or properties needs to be internal or public (not private) for them to be visible to other forms in the same application.
In the case of controls, the access can be changed via the Modifiers property in the Properties Box for the control.
VulpesPosted Apr 19, 2013, 6:52 PM
Tamas SzigetiPosted Apr 19, 2013, 4:00 AM