I have a Form1 and I do some processing in the other class.
What would be the proper way to output information to Form1 textBox9 ?
This is how I do it, but it only work partially, only when the form is active.
This is what I have in my class:
var form = Form.ActiveForm as Form1;
if (form != null)
{
form.updateLabel("DBadd[" + counter + "]" + NAME2);
}
This is that I have in my Form1:
delegate void updateStatus(String value);
public void updateLabel(String value)
{
if (textBox9.InvokeRequired)
{
updateStatus del = new updateStatus(updateCodemicroLabel);
textBox9.Invoke(del, new object[] { value });
}
else
{
{
textBox9.Text = value;
}
}
}
This is how my class called:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
new className().runTask();
}
Instead of using
Form.ActiveFormyou need to pass the instance to the class so it can callwhatever.updateLabel()withwhateverbeing the instance.