So this is my code:

```
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (listBox1.SelectedItem.ToString()=="Light" && Form.ActiveForm.Name != "Light")
        {
            Light o = new Light();
            o.Show();
            o.listBox1.SelectedIndex = listBox1.SelectedIndex;
            NeedsToClose = false;
            this.Close();
        }
        else if(listBox1.SelectedItem.ToString() == "Acceleration"&& Form.ActiveForm.Name !="Acceleration")
        {
            Acceleration o = new Acceleration();
            o.Show();
            o.listBox1.SelectedIndex = listBox1.SelectedIndex;
            NeedsToClose = false;
            this.Close();
        }

    }

```

It works, but as you can see I have this part of code in both cases:

```
o.Show();
o.listBox1.SelectedIndex = listBox1.SelectedIndex;
NeedsToClose = false;
this.Close();

```

I would like to make it function(void) instead, pass an object to it, and get a result. Any ideas how this can be done? 

Both Forms derive from form called Template,which derives from class Form.