In my project, I'm dynamically generating a lot of elements on a form, like buttons, picture boxes etc.
To separate the code, I'll be making new classes. I've made an instance of form1 in my new class, but all the elements are inaccessible -- why is this?
Edit: below is the relevant code. I'm trying to create buttons in CreateParty
, but when I reference an element in form1 (in this case gameScrollBar
), I get an error
Inaccesible due to its protection level
My code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CreateParty createparty = new CreateParty(this);
generateIcons();
}
}
public class CreateParty
{
private Form1 mainForm;
public CreateParty(Form1 form1)
{
mainForm = form1;
testVoid();
}
public void testVoid()
{
Button NAButton = new Button();
NAButton.Height = 100;
NAButton.Width = 100;
NAButton.Location = new Point(190, 100);
NAButton.Text = "NA";
mainForm.gameScrollBar.Controls.Add(NAButton);
}
}
Any insight would be greatly appreciated.