Click here to Skip to main content
15,910,787 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all

I call to another form with name frmSearch.

C#
frmSearch fsearch = new frmSearch("formName", this);
fsearch.Show();

public frmSearch(string formName, Form  _form)
{
  switch  (formName)
     {
     case "client":
                   _form.txtBoxclient.Text  = value; //Error can not find control
                break;
                case "provider":
                   _form.txtBoxprovidet.Text  = value; //Error can not find control
}



the function frmSearch(string formName, Form _for) can receive any forms for example(frmManagementFile, frmClient,....)

In vb.net this funcionality run well.

How to i can modify the value of control of diferent forms with only one method public frmSearch(string formName, Form _form) ?

Regards and thank's
Posted
Updated 29-Sep-11 5:23am
v2
Comments
RaisKazi 29-Sep-11 11:24am    
Formatted using "pre" and "code" tags.
Sergey Alexandrovich Kryukov 29-Sep-11 20:19pm    
My vote of one for the attempt to identify forms by sting names. They are class instances, have references.
--SA

1 solution

Well, you're passing in a normal Windows Form. Normal forms do not have txtBoxclient and txBoxprodidet, so that's why you have the error. You'd need to change the constructor to take a derived Form which does have these controls for this to work.

btw, don't use '_form' for locals, just 'form'
 
Share this answer
 
Comments
tgarijo 29-Sep-11 11:52am    
Thank You Can you write me an example.
Rob Philpott 29-Sep-11 12:31pm    
Replace Form in the constructor with the form with buttons on it, or, if you're completely mad for it and using .NET4 replace it with 'dynamic'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900