The following example is in your main form. This can be called from your
main form *or from another thread which can be your class1. You just need
to pass the form ref to your class constructor or set a public static or
something so that class1 knows how to reference
"Form.UpdateDelegate("sometext");" (for example.) Note the InvokeRequired
and delegate stuff is there to make any calls from other threads are
queued
to UI thread as you should not call UI controls from other threads.
Moreover, you can use this method to update any control in your forms
(pBars, etc.) Just create the right delegate and use the UpdateLabel
template as example for you new method. hth
private delegate void UpdateDelegate(string value);
public void UpdateLabel(string text)
{
if ( text == null )
throw new ArgumentNullException("text");
if ( InvokeRequired )
{
UpdateDelegate ud = new UpdateDelegate(UpdateLabel);
this.BeginInvoke(ud, new object[]{text});
}
else
{
this.label1.Text = text;
}
}
--
William Stacey, MVP
http://mvp.support.microsoft.com
TomTom said:
I think my question was not clear. Here is a simpler scenario. If I want to
show text "Finished!" on myLabel1 on Form1 from Class1, how should I do it?
If I do this from the code behind of Form1, I can just write
myLabel1.Text =
"Finished!", but I don't know how I can do this from Class1.