I need to change the text of a label on a C# Winform that is already open. The form was opened from a different method in my program so it is already open and I don't have access to the original reference of the form when it was first created.
I tried to do this in the code below, but I can not access the label on the form. Is there a way I can change the label on a form (from another method) that is already running?
//http://stackoverflow.com/questions/3861602/c-sharp-how-check-if-the-form-is-already-open-and-close-it-if-it-does
Form fc = Application.OpenForms["form1"];
if (fc != null)
{
//This does not work. I can not access the lblNewItems label.
//The label has it's public modifier set to Public and I am able
//to set this label successfully when I create the form originally
//from the other method.
fc.lblNewItems.Text = "Change text";
}
When compiling the above I get the following error:
Error 4 'System.Windows.Forms.Form' does not contain a definition for 'lblNewItems' and no extension method 'lblNewItems' accepting a first argument of type 'System.Windows.Forms.Form' could be found (are you missing a using directive or an assembly reference?)
Can someone please tell me if this is possible to do and if so; how do I change the label on a form that is already opened from another method?