Abanoub - If I understand what you are trying to do - you want to set the label of an already displayed form without creating a new instance of the form. At least one way to do that would be with a singleton class that holds the form instance. So there will only be one instance of the form. Please try the following:
First, we create a singleton class that keeps the form instance:
public class Singleton
{
// Modified from: http://csharpindepth.com/articles/general/singleton.aspx
// This will keep ONE instance of the Admin Form
private Admin _adminForm;
public Admin AdminForm
{
get
{
if (_adminForm == null)
{
_adminForm = new Admin();
}
return _adminForm;
}
}
private static Singleton instance = null;
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
Now you instantiate the from from this instance - for example:
Button 1 will display the form:
private void button1_Click(object sender, EventArgs e)
{
var singleton = Singleton.Instance;
var f = singleton.AdminForm;
f.Show();
}
Button 2 will set the already displayed form's label (BTW - I think you want the property to set the text of the label not the label right?)
private void button2_Click(object sender, EventArgs e)
{
// Assuming you clicked button 1 first,
// this will not cause a new instance but use the existing one
var singleton = Singleton.Instance;
var f = singleton.AdminForm;
f.LabelText = "Hello world!";
}
Assuming you want to set the text of the label - here is the modified property in Admin:
public string LabelText
{
get { return label8.Text; }
set { label8.Text = value; }
}
I hope this will be helpful to you - good luck!!