I have made the move from VB.net to C#. I have a quick question regarding calling/showing child forms. In VB.Net when i need to show Form2 from Form1 i simple call Form2.Show from inside a button1 event. In C# i have found that i have to do the following :-
- Code: Select all
VB
Form2.Show();
c# -
KrypronForm myForm2 = new Form2();
myForm2.Show();
I guess this is because VB creates the new instance for you?
This one took me a while, if i had a function written on Form1 that was made public, in VB if i needed to call the function from Form2 i simple did Form1.myTest(). But as i understand you cannot do this in C#: -
- Code: Select all
VB
Form1.myFunction()
C#
private Form1 m_form1;
// Code in the Form2 constructor
public Form2(Form1 frm1)
{
InitializeComponent();
m_form1 = frm1;
}
// Call function
m_form1.myFunction();
My question is: is there a more elegant way of calling a function on Form1 (parent form) from the child form (Form2)? (other than making it a static function)
Thanks
Xplosiv