Reference controls from another form

  • Thread starter Thread starter Taryon
  • Start date Start date
T

Taryon

Consider the Form A calling the Form B. In the Form B i need to access the
values of the Form A textbox.
Normally i create the textbox as public. BUT in this case, the textbox of
Form A will be created on the fly and i cant use the MODIFIERS.
Anyone has an idea how to do it?
 
Create a public variable (or property) in Form B. When you create Form B
set the property to the textbox. That will give full access to the control.

Lloyd Sheen
 
I cant. Remember i cannot access the textbox because it is in the Form A.
the caller form.
This is all i want.
 
oh. i understand.
let me try.
thanks
Lloyd Sheen said:
Create a public variable (or property) in Form B. When you create Form B
set the property to the textbox. That will give full access to the control.

Lloyd Sheen
 
I cannot do it. can you give an example?
i create in the FORM2 a:

public static TextBox tb1;

and in the form1 i have:

private void tb_DoubleClick(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)sender;
Form frm = createForm(frmnx++);
< in this point i try to find the frm.tb1 but i cannot see it.
frm.ShowDialog();

the create form is:

private Form createForm(int ix)
{
tabela frm = new tabela();
frm.Name = "frm"+ix.ToString();
frm.Tag= ix;
return frm;
}

I created one public static array structure to hold the fields and its
values. This struct i can see from FORM2.
but i need to know what textbox is calling the form.
 
From what I see in your code you may have the following problem. You are
using a generic Form as the variable. Since the Form class has no knowledge
of the public variable tb1 it will for sure not show in intellisence. What
you are doing is late binding. I am more familiar with VB.NET but I would
make all forms implement an interface with one method which sets the textbox
into the form. Then call this method after the form is created to populate
the variable.

Lloyd Sheen
 
Back
Top