Windows Forms, problem z stworzeniem listy obiektów

0

Cześć.
Próbuję napisać grę 2048 (ta z przesuwaniem kwadratów, do momentu aż nie zsumuje się ich do liczby 2048),
te kwadraty reprezentują u mnie obiekty klasy "PictureBox", po wywołaniu metody "InitializeComponent()" chcę je wszystkie dodać do listy, żeby później podczas ich przesuwania móc sobie iterować bez problemu po nich.
Tylko, że gdy próbuję je dodać do tej listy, okazuje się, że one jakby w ogóle nie istnieją.
Nie mam pomysłu co jest nie tak.
A tak przy okazji, czy coś lepiej się nada - jako reprezentacja tych przesuwającyh się kwadratów - zamiast klasy PictureBox? :)

Tutaj wywołuję pętlę, żeby sprawdzić wszystkie kontrolki, konsola nie wypluwa żadnej nazwy:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2048_Game
{
    public partial class mainWindowForm : Form
    {
        private List<PictureBox> digit_squares = new List<PictureBox>();

        public mainWindowForm()
        {
            InitializeComponent();
            foreach(Control c in this.Controls)
            {
                Console.WriteLine(c.Name);
            }
        }

        private void mainWindowForm_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyData == Keys.Right)
            {
                
            }
        }
    }
}

Tutaj są tworzone instancje klasy PictureBox:

namespace _2048_Game
{
    partial class mainWindowForm
    {
        /// <summary>
        /// Wymagana zmienna projektanta.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Wyczyść wszystkie używane zasoby.
        /// </summary>
        /// <param name="disposing">prawda, jeżeli zarządzane zasoby powinny zostać zlikwidowane; Fałsz w przeciwnym wypadku.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Kod generowany przez Projektanta formularzy systemu Windows

        /// <summary>
        /// Metoda wymagana do obsługi projektanta — nie należy modyfikować
        /// jej zawartości w edytorze kodu.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(mainWindowForm));
            this.menuStrip = new System.Windows.Forms.MenuStrip();
            this.graToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.nowaGraToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.wyjdźToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mainPanel = new System.Windows.Forms.Panel();
            this.box16 = new System.Windows.Forms.PictureBox();
            this.box15 = new System.Windows.Forms.PictureBox();
            this.box14 = new System.Windows.Forms.PictureBox();
            this.box13 = new System.Windows.Forms.PictureBox();
            this.box12 = new System.Windows.Forms.PictureBox();
            this.box11 = new System.Windows.Forms.PictureBox();
            this.box10 = new System.Windows.Forms.PictureBox();
            this.box9 = new System.Windows.Forms.PictureBox();
            this.box8 = new System.Windows.Forms.PictureBox();
            this.box7 = new System.Windows.Forms.PictureBox();
            this.box6 = new System.Windows.Forms.PictureBox();
            this.box5 = new System.Windows.Forms.PictureBox();
            this.box4 = new System.Windows.Forms.PictureBox();
            this.box3 = new System.Windows.Forms.PictureBox();
            this.box2 = new System.Windows.Forms.PictureBox();
            this.box1 = new System.Windows.Forms.PictureBox();
            this.menuStrip.SuspendLayout();
            this.mainPanel.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.box16)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box15)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box14)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box13)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box12)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box11)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box10)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box9)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box8)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box7)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box6)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box5)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box4)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.box1)).BeginInit();
            this.SuspendLayout();
            // 
            // menuStrip
            // 
            this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.graToolStripMenuItem});
            this.menuStrip.Location = new System.Drawing.Point(0, 0);
            this.menuStrip.Name = "menuStrip";
            this.menuStrip.Size = new System.Drawing.Size(489, 24);
            this.menuStrip.TabIndex = 0;
            this.menuStrip.Text = "menuStrip1";
            // 
            // graToolStripMenuItem
            // 
            this.graToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.nowaGraToolStripMenuItem,
            this.wyjdźToolStripMenuItem});
            this.graToolStripMenuItem.Name = "graToolStripMenuItem";
            this.graToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.graToolStripMenuItem.Text = "Gra";
            // 
            // nowaGraToolStripMenuItem
            // 
            this.nowaGraToolStripMenuItem.Name = "nowaGraToolStripMenuItem";
            this.nowaGraToolStripMenuItem.Size = new System.Drawing.Size(126, 22);
            this.nowaGraToolStripMenuItem.Text = "Nowa Gra";
            // 
            // wyjdźToolStripMenuItem
            // 
            this.wyjdźToolStripMenuItem.Name = "wyjdźToolStripMenuItem";
            this.wyjdźToolStripMenuItem.Size = new System.Drawing.Size(126, 22);
            this.wyjdźToolStripMenuItem.Text = "Wyjdź";
            // 
            // mainPanel
            // 
            this.mainPanel.BackColor = System.Drawing.SystemColors.ActiveBorder;
            this.mainPanel.Controls.Add(this.box16);
            this.mainPanel.Controls.Add(this.box15);
            this.mainPanel.Controls.Add(this.box14);
            this.mainPanel.Controls.Add(this.box13);
            this.mainPanel.Controls.Add(this.box12);
            this.mainPanel.Controls.Add(this.box11);
            this.mainPanel.Controls.Add(this.box10);
            this.mainPanel.Controls.Add(this.box9);
            this.mainPanel.Controls.Add(this.box8);
            this.mainPanel.Controls.Add(this.box7);
            this.mainPanel.Controls.Add(this.box6);
            this.mainPanel.Controls.Add(this.box5);
            this.mainPanel.Controls.Add(this.box4);
            this.mainPanel.Controls.Add(this.box3);
            this.mainPanel.Controls.Add(this.box2);
            this.mainPanel.Controls.Add(this.box1);
            this.mainPanel.Location = new System.Drawing.Point(12, 27);
            this.mainPanel.Name = "mainPanel";
            this.mainPanel.Size = new System.Drawing.Size(464, 409);
            this.mainPanel.TabIndex = 18;
            // 
            // box16
            // 
            this.box16.Image = ((System.Drawing.Image)(resources.GetObject("box16.Image")));
            this.box16.Location = new System.Drawing.Point(355, 302);
            this.box16.Name = "box16";
            this.box16.Size = new System.Drawing.Size(85, 85);
            this.box16.TabIndex = 15;
            this.box16.TabStop = false;
            // 
            // box15
            // 
            this.box15.Image = ((System.Drawing.Image)(resources.GetObject("box15.Image")));
            this.box15.Location = new System.Drawing.Point(244, 302);
            this.box15.Name = "box15";
            this.box15.Size = new System.Drawing.Size(85, 85);
            this.box15.TabIndex = 14;
            this.box15.TabStop = false;
            // 
            // box14
            // 
            this.box14.Image = ((System.Drawing.Image)(resources.GetObject("box14.Image")));
            this.box14.Location = new System.Drawing.Point(133, 302);
            this.box14.Name = "box14";
            this.box14.Size = new System.Drawing.Size(85, 85);
            this.box14.TabIndex = 13;
            this.box14.TabStop = false;
            // 
            // box13
            // 
            this.box13.Image = ((System.Drawing.Image)(resources.GetObject("box13.Image")));
            this.box13.Location = new System.Drawing.Point(22, 302);
            this.box13.Name = "box13";
            this.box13.Size = new System.Drawing.Size(85, 85);
            this.box13.TabIndex = 12;
            this.box13.TabStop = false;
            // 
            // box12
            // 
            this.box12.Image = ((System.Drawing.Image)(resources.GetObject("box12.Image")));
            this.box12.Location = new System.Drawing.Point(355, 206);
            this.box12.Name = "box12";
            this.box12.Size = new System.Drawing.Size(85, 85);
            this.box12.TabIndex = 11;
            this.box12.TabStop = false;
            // 
            // box11
            // 
            this.box11.Image = ((System.Drawing.Image)(resources.GetObject("box11.Image")));
            this.box11.Location = new System.Drawing.Point(244, 206);
            this.box11.Name = "box11";
            this.box11.Size = new System.Drawing.Size(85, 85);
            this.box11.TabIndex = 10;
            this.box11.TabStop = false;
            // 
            // box10
            // 
            this.box10.Image = ((System.Drawing.Image)(resources.GetObject("box10.Image")));
            this.box10.Location = new System.Drawing.Point(133, 206);
            this.box10.Name = "box10";
            this.box10.Size = new System.Drawing.Size(85, 85);
            this.box10.TabIndex = 9;
            this.box10.TabStop = false;
            // 
            // box9
            // 
            this.box9.Image = ((System.Drawing.Image)(resources.GetObject("box9.Image")));
            this.box9.Location = new System.Drawing.Point(22, 206);
            this.box9.Name = "box9";
            this.box9.Size = new System.Drawing.Size(85, 85);
            this.box9.TabIndex = 8;
            this.box9.TabStop = false;
            // 
            // box8
            // 
            this.box8.Image = ((System.Drawing.Image)(resources.GetObject("box8.Image")));
            this.box8.Location = new System.Drawing.Point(355, 110);
            this.box8.Name = "box8";
            this.box8.Size = new System.Drawing.Size(85, 85);
            this.box8.TabIndex = 7;
            this.box8.TabStop = false;
            // 
            // box7
            // 
            this.box7.Image = ((System.Drawing.Image)(resources.GetObject("box7.Image")));
            this.box7.Location = new System.Drawing.Point(244, 110);
            this.box7.Name = "box7";
            this.box7.Size = new System.Drawing.Size(85, 85);
            this.box7.TabIndex = 6;
            this.box7.TabStop = false;
            // 
            // box6
            // 
            this.box6.Image = ((System.Drawing.Image)(resources.GetObject("box6.Image")));
            this.box6.Location = new System.Drawing.Point(133, 110);
            this.box6.Name = "box6";
            this.box6.Size = new System.Drawing.Size(85, 85);
            this.box6.TabIndex = 5;
            this.box6.TabStop = false;
            // 
            // box5
            // 
            this.box5.Image = ((System.Drawing.Image)(resources.GetObject("box5.Image")));
            this.box5.Location = new System.Drawing.Point(22, 110);
            this.box5.Name = "box5";
            this.box5.Size = new System.Drawing.Size(85, 85);
            this.box5.TabIndex = 4;
            this.box5.TabStop = false;
            // 
            // box4
            // 
            this.box4.Image = ((System.Drawing.Image)(resources.GetObject("box4.Image")));
            this.box4.Location = new System.Drawing.Point(355, 14);
            this.box4.Name = "box4";
            this.box4.Size = new System.Drawing.Size(85, 85);
            this.box4.TabIndex = 3;
            this.box4.TabStop = false;
            // 
            // box3
            // 
            this.box3.Image = ((System.Drawing.Image)(resources.GetObject("box3.Image")));
            this.box3.Location = new System.Drawing.Point(244, 14);
            this.box3.Name = "box3";
            this.box3.Size = new System.Drawing.Size(85, 85);
            this.box3.TabIndex = 2;
            this.box3.TabStop = false;
            // 
            // box2
            // 
            this.box2.Image = ((System.Drawing.Image)(resources.GetObject("box2.Image")));
            this.box2.Location = new System.Drawing.Point(133, 14);
            this.box2.Name = "box2";
            this.box2.Size = new System.Drawing.Size(85, 85);
            this.box2.TabIndex = 1;
            this.box2.TabStop = false;
            // 
            // box1
            // 
            this.box1.Image = ((System.Drawing.Image)(resources.GetObject("box1.Image")));
            this.box1.Location = new System.Drawing.Point(22, 14);
            this.box1.Name = "box1";
            this.box1.Size = new System.Drawing.Size(85, 85);
            this.box1.TabIndex = 0;
            this.box1.TabStop = false;
            // 
            // mainWindowForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(489, 448);
            this.Controls.Add(this.menuStrip);
            this.Controls.Add(this.mainPanel);
            this.MainMenuStrip = this.menuStrip;
            this.Name = "mainWindowForm";
            this.Text = "2048";
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mainWindowForm_KeyDown);
            this.menuStrip.ResumeLayout(false);
            this.menuStrip.PerformLayout();
            this.mainPanel.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.box16)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box15)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box14)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box13)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box12)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box11)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box10)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box9)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box8)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box7)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box6)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box5)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box4)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.box1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip;
        private System.Windows.Forms.ToolStripMenuItem graToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem nowaGraToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem wyjdźToolStripMenuItem;
        private System.Windows.Forms.Panel mainPanel;
        private System.Windows.Forms.PictureBox box1;
        private System.Windows.Forms.PictureBox box2;
        private System.Windows.Forms.PictureBox box16;
        private System.Windows.Forms.PictureBox box15;
        private System.Windows.Forms.PictureBox box14;
        private System.Windows.Forms.PictureBox box13;
        private System.Windows.Forms.PictureBox box12;
        private System.Windows.Forms.PictureBox box11;
        private System.Windows.Forms.PictureBox box10;
        private System.Windows.Forms.PictureBox box9;
        private System.Windows.Forms.PictureBox box8;
        private System.Windows.Forms.PictureBox box7;
        private System.Windows.Forms.PictureBox box6;
        private System.Windows.Forms.PictureBox box5;
        private System.Windows.Forms.PictureBox box4;
        private System.Windows.Forms.PictureBox box3;
        
    }
}


1
foreach(var pb in this.Controls.OfType<PictureBox>())

Pod warunkiem, że one są w bezpośrednio na formie

1 użytkowników online, w tym zalogowanych: 0, gości: 1