mardi 31 mars 2015

Passing form object to another method

Im trying to pass a form object from the method that creates it to one that will show it and set a few properties on it, instead of having the smae code in each button event. Im getting the error "Argument 1: cannot convert from 'ref RWCStatTracker.Fixture.FRMAddFixture' to 'ref System.Windows.Forms.Form'" and "The best overloaded method match for 'RWCStatTracker.Form1.showForm(ref System.Windows.Forms.Form)' has some invalid arguments" These are occuring on line 70 in the button click event where it has showForm(ref frm);



public void addToolStripMenuItem3_Click(object sender, EventArgs e)
{
RWCStatTracker.Fixture.FRMAddFixture frm = new RWCStatTracker.Fixture.FRMAddFixture();
showForm(ref frm);
}

public void showForm(ref Form frm)
{
frm.TopLevel = false; //set it's TopLevel to false

Controls.Add(frm); //and add it to the parent Form
frm.Show(); //finally display it

frm.BringToFront(); //use this it there are Controls over your form.
}


I've found many articles on google but none are really achieving what im trying to achieve


Any ideas how I can make this work?


Aucun commentaire:

Enregistrer un commentaire