Since you have declared Project as
public
it is available to all classes that can reference the assembly / namespace.
public class Project
{
...
}
There is nothing stopping you from using it in ProjectGlobals
public static class ProjectGlobals
{
List<Project> ProjectArray = new List<Project>();
}
(Note that I have replaces ArrayList with the generic List<>: they are very, very similar, but a List<Project>will only hold projects, and you do not need to cast the contecnts when you use them)
Your problem is a bit more fundamental:
private void btnOkay_Click(object sender, EventArgs e)
{
Project Projects = new Project();
Projects.sName = txtProjectName.Text;
this.Close();
}
The method Creates an instance of a Project, and assigns a name to it. It then closes the form it is in. This makes doubly sure that the instance is discarded as it is out of scope!.
I assume that you are trying to set up a dialog to get a name for a new project?
If so, you could either:
1) Return the Project name via a property and let the calling form create the project and add it to it's list.
2) Return a completed Project via a property.
3) Mess about with a static as you are.
I would go with the first option: That way the same dialog can be re-used to change the name of a project.
The route you are taking is very messy, and there are much simpler ways to do it:
Main Form:
private List<Project> Projects = new List<Project>();
...
AddProjectForm apf = new AddProjectForm();
if (apf.ShowDialog() == DialogResult.OK)
{
Projects.Add(new Project(apf.ProjectName));
}
...
}
AddProjectForm:
public string ProjectName
{
get { return txtProjectName.Text; }
set { txtProjectName.Text = value }
}
You do not need the ProjectGlobals class at all.