问题
I want to use a textBox
, which is on my main form Form1
from other class. In class Form1
I can use:
this.Invoke(new EventHandler(displayText));
and then
private void displayAccFields(object o, EventArgs e)
{
tbAccRoll.AppendText(packParameters.getPackage(3) + "");
}
and it works fine.
How can I access this textbox
for displaying something from a different class?
回答1:
For sending values between two forms, you may
- Send the values in the constructor of the second form. You may create a paramterized constructor and send the values when you initialize the form.
- You may take a reference in to your first form in the second form.
In second form,
public Form1 objForm1;
and in First Form,
Form2 objForm2=new Form2();
Form2.objForm1=this;
and then you can use Form2's objForm1 to refer to Form1's textbox.
来源:https://stackoverflow.com/questions/15766636/access-a-textbox-from-another-class-in-workspace