Not sure, but it seems to me that you want to perform this code:
form.btnNewInvoice.PerformClick();
form.txtInvoiceNo.Text = invNo;
form.dataGridView1.Focus();
for when the form is already open. You say that, "Its not working and not able to pass PARAMETER". Most likely you are trying to use "f" in the snippet below?
if (f.GetType() == typeof(PurchaseForm ))
{
f.Visible = true;
f.Activate();
.....
}
If so, just cast "f" to PurchaseForm like this:
if (f.GetType() == typeof(PurchaseForm ))
{
PurchaseForm pf = (PurchaseForm)f;
pf.btnNewInvoice.PerformClick();
pf.txtInvoiceNo.Text = invNo;
pf.dataGridView1.Focus();
pf.Visible = true;
pf.Activate();
.....
}
EDIT: Simple example of what Servy is talking about...
Basically you'd create a public method to receive the invoice number. That method can access the controls and set values directly. Something like this:
public partial class PurchaseForm : Form
{
public void SetInvoiceNumber(string invNo)
{
this.Visible = true;
this.Activate();
this.txtInvoiceNo.Text = invNo;
this.btnNewInvoice.PerformClick();
this.dataGridView1.Focus();
}
}
Then, after casting "f" to PurchaseForm (as shown previously), you'd just do:
if (f.GetType() == typeof(PurchaseForm ))
{
PurchaseForm pf = (PurchaseForm)f;
pf.SetInvoiceNumber(invNo);
}