I have a Control lblDate
in User Control MainScreen
. I would like to modify it in a method in class Date
, which is in another project
I'd rather advise you make your GameDate method to return a string then call it from your main project which are essentially what libraries are meant for. e.g.:
public static string CalculateDate()
{
return month.ToString() + "/" + displayDay.ToString() + "/" + year.ToString();
}
//in your main project
LabelDate.Text = myLibrary.CalculateDate();
For accessing it from other controls in the same project, you should use a delegate - Provide a delegate which performs the addition, declare the delegate and invoke the function from your CaculateDate
. Example:
public delegate void dateSet(string);
public void setDate(string date)
{
labelDate.Text = date;
}
then in your CaculateDate
method:
labeldate.Invoke(new MainForm.dateSet(), GameDate);