YES! Now it seems to function properly!
Here the code that did the trick.
The UserControl that features the components whose properties I want to change:
public partial class UserControlGame : UserControl
{
public UserControlGame()
{
InitializeComponent();
for (int i = 0; i < GlobalVariables.configsetup[0]; i++)
{
SlotField[i] = new System.Windows.Forms.Panel();
SlotContainer[i] = new Microsoft.VisualBasic.PowerPacks.ShapeContainer();
SlotForm[i] = new Microsoft.VisualBasic.PowerPacks.OvalShape();
flowLayoutPanel1.Controls.Add(SlotField[i]);
SlotField[i].Controls.Add(SlotContainer[i]);
SlotField[i].Margin = new System.Windows.Forms.Padding(5);
SlotField[i].Name = "SlotField" + (i + 1).ToString();
SlotField[i].Size = new System.Drawing.Size(50, 50);
SlotField[i].TabIndex = 0;
SlotField[i].TabStop = false;
SlotContainer[i].Location = new System.Drawing.Point(0, 0);
SlotContainer[i].Margin = new System.Windows.Forms.Padding(0);
SlotContainer[i].Name = "SlotContainer" + (i + 1).ToString();
SlotContainer[i].Shapes.AddRange(new Microsoft.VisualBasic.PowerPacks.Shape[] { SlotForm[i] });
SlotContainer[i].Size = new System.Drawing.Size(50, 50);
SlotContainer[i].TabIndex = 0;
SlotContainer[i].TabStop = false;
SlotForm[i].BorderColor = System.Drawing.Color.Black;
SlotForm[i].BorderWidth = 6;
SlotForm[i].Enabled = false;
SlotForm[i].FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
SlotForm[i].FillStyle = Microsoft.VisualBasic.PowerPacks.FillStyle.Solid;
SlotForm[i].Location = new System.Drawing.Point(5, 5);
SlotForm[i].Name = "SlotForm" + (i + 1).ToString();
SlotForm[i].Size = new System.Drawing.Size(34, 34);
}
}
MindMasterColourForm ColourForm;
System.Windows.Forms.Panel[] SlotField = new System.Windows.Forms.Panel[GlobalVariables.configsetup[0]];
Microsoft.VisualBasic.PowerPacks.ShapeContainer[] SlotContainer = new Microsoft.VisualBasic.PowerPacks.ShapeContainer[GlobalVariables.configsetup[0]];
Microsoft.VisualBasic.PowerPacks.OvalShape[] slotForm = new Microsoft.VisualBasic.PowerPacks.OvalShape[GlobalVariables.configsetup[0]];
public Microsoft.VisualBasic.PowerPacks.OvalShape[] SlotForm
{
get
{
return slotForm; // returns ref to your array
}
set
{
slotForm = value; // sets your array to a new ref
}
}
private void buttonSetUp_Click(object sender, EventArgs e)
{
Hide();
ColourForm.Close();
BasicFunctions.setuppage();
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Hide();
ColourForm.Close();
BasicFunctions.startpage();
}
private void UserControlGame_Load(object sender, EventArgs e)
{
ColourForm = new MindMasterColourForm(this);
ColourForm.Location = new Point(this.Parent.Location.X + 521, this.Parent.Location.Y + 381);
ColourForm.Show();
GlobalVariables.position = new int[GlobalVariables.configsetup[2] + 1, GlobalVariables.configsetup[0] + 2];
int[] colorvec;
colorvec = new int[GlobalVariables.configsetup[1]];
Random rand = new Random();
}
}
And now the Form from which I want to control the properties:
public partial class MindMasterColourForm : Form
{
UserControlGame ucg;
public MindMasterColourForm(UserControlGame ucgParam)
{
InitializeComponent();
ucg = ucgParam;
for (int i = 0; i < GlobalVariables.configsetup[1]; i++)
{
ColourButton[i] = new System.Windows.Forms.Button();
this.buttonClear = new System.Windows.Forms.Button();
ColourButton[i].Parent = this;
ColourButton[i].BackColor = System.Drawing.Color.FromArgb(BasicFunctions.SetColour(i + 1)[0], BasicFunctions.SetColour(i + 1)[1], BasicFunctions.SetColour(i + 1)[2]);
if (i > GlobalVariables.configsetup[1]/2) ColourButton[i].Location = new System.Drawing.Point(20 + (i - 1 - GlobalVariables.configsetup[1] / 2) * 58, 62);
else ColourButton[i].Location = new System.Drawing.Point(20 + i * 58, 20);
ColourButton[i].Margin = new System.Windows.Forms.Padding(10);
ColourButton[i].Name = (i + 1).ToString();
ColourButton[i].Size = new System.Drawing.Size(48, 32);
ColourButton[i].TabIndex = 0;
ColourButton[i].Text = (i + 1).ToString();
ColourButton[i].UseVisualStyleBackColor = false;
ColourButton[i].Click += new System.EventHandler(ColourClicker_Click);
this.Controls.Add(ColourButton[i]);
buttonClear.Parent = this;
buttonClear.Location = new System.Drawing.Point(83 + ((GlobalVariables.configsetup[1] / 2)) * 58, 20);
buttonClear.Margin = new System.Windows.Forms.Padding(5, 20, 20, 10);
buttonClear.Name = "buttonClear";
buttonClear.Size = new System.Drawing.Size(48, 84);
buttonClear.TabIndex = 1;
buttonClear.Text = "Clear";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += new System.EventHandler(buttonClear_Click);
ClientSize = new System.Drawing.Size(151 + ((GlobalVariables.configsetup[1] / 2)) * 58, 124);
}
}
System.Windows.Forms.Button[] ColourButton = new System.Windows.Forms.Button[GlobalVariables.configsetup[1]];
private void MindMasterColourForm_Load(object sender, EventArgs e)
{
GlobalVariables.colorinputcounter = 0;
}
private void ColourClicker_Click(object sender, EventArgs e)
{
GlobalVariables.tempcolorinput[GlobalVariables.colorinputcounter] = int.Parse(((Button)sender).Text);
ucg.SlotForm[GlobalVariables.colorinputcounter].FillColor = System.Drawing.Color.FromArgb(BasicFunctions.SetColour(int.Parse(((Button)sender).Text))[0], BasicFunctions.SetColour(int.Parse(((Button)sender).Text))[1], BasicFunctions.SetColour(int.Parse(((Button)sender).Text))[2]);
ucg.SlotForm[GlobalVariables.colorinputcounter].BorderWidth = 2;
ucg.SlotForm[GlobalVariables.colorinputcounter].Location = new System.Drawing.Point(3, 3);
ucg.SlotForm[GlobalVariables.colorinputcounter].Size = new System.Drawing.Size(38, 38);
if (GlobalVariables.colorinputcounter < GlobalVariables.configsetup[0] - 1)
{
GlobalVariables.colorinputcounter += 1;
}
else
{
for (int i = 0; i < GlobalVariables.configsetup[1]; i++)
{
ColourButton[i].Enabled = false;
}
}
}
private void buttonClear_Click(object sender, EventArgs e)
{
for (int i = 0; i < GlobalVariables.configsetup[0]; i++)
{
GlobalVariables.tempcolorinput[i] = 0;
ucg.SlotForm[i].FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
ucg.SlotForm[i].BorderWidth = 6;
ucg.SlotForm[i].Location = new System.Drawing.Point(5, 5);
ucg.SlotForm[i].Size = new System.Drawing.Size(34, 34);
}
for (int i = 0; i < GlobalVariables.configsetup[1]; i++)
{
ColourButton[i].Enabled = true;
}
GlobalVariables.colorinputcounter = 0;
}
}
The advantage over the much simpler way of declaring
SlotForm in the UserControlGame once as
public static is that the array
Microsoft.VisualBasic.PowerPacks.OvalShape[] slotForm = new Microsoft.VisualBasic.PowerPacks.OvalShape[x]; can have a variable size, i.e.,
x is a variable, while initializing it as static it won't change during runtime. That means, even if
x is a variable, the size (Length) of the array will keep it's initial value, even when
x changes. (At least that's what I have seen so far. Correct me if this is wrong.)