Can someone help with controls? (C# Windows Froms)
I need help using controls from different forms, for example:
Form1 has a checkbox
Form2 has a button
When you click the button on form2 then the checkbox on form1 is checked
I don't really advice you doing such thing.. but here is a solution (Among toons of them).
Simply create your starting form at Program.cs globally and access it's controls anywhere in the program.
[php]static class Program
{
public static Form1 mainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(mainForm = new Form1());
}
}
[/php]
to access:
[php]((CheckBox)Program.mainForm.Controls["chkForm1"]).Checked = true;[/php]
Although i don't really advice this. You can also create methods, proprieties, etc.. change your controls modifier to public or internal.. w/e
Just play around with those objects/proprieties.