The modifiers need to be public and this code is a little tricky if you haven't ever done it. I've made a sample program to show how it is done.
The application is two forms and a button on each form. The button on the first form launches form2. The button on form2 calls a function in form1. In order to get the parent you have to pass the form1 instance to form2 on creation (in the constructor). Look below to see how it is done.
Form1.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace childform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 tempDialog = new Form2(this);
tempDialog.ShowDialog();
}
public void msgme()
{
MessageBox.Show("Parent Function Called");
}
}
}
Form2.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace childform
{
public partial class Form2 : Form
{
private Form1 m_parent;
public Form2(Form1 frm1)
{
InitializeComponent();
m_parent = frm1;
}
private void button1_Click(object sender, EventArgs e)
{
m_parent.msgme();
}
}
}
Should Produce a msgbox with "Parent Function Called"