private void OnImageChange(Object sender, EventArgs args)
        {
            PictureBoxControl pb1 = sender as PictureBoxControl;

            if (pb1.PictureBox.Image is null)
            {
                ;
            }
            else
            {
                this.addButtons.Add(pb1.btn_AddToTrack);
            }
        }
        private void GenerateTable(int columnCount, int rowCount)
        {
            this.TableLayoutPanel = new TableLayoutPanel();

            PictureBoxControl tempPicBox     = new PictureBoxControl();
            int pictureBoxControlTotalHeight = tempPicBox.Height + (tempPicBox.Margin.Bottom + tempPicBox.Margin.Top);
            int pictureBoxControlTotalWidth  = tempPicBox.Width + (2 * tempPicBox.Margin.Left);

            this.TableLayoutPanel.Controls.Clear();

            this.TableLayoutPanel.ColumnStyles.Clear();
            this.TableLayoutPanel.RowStyles.Clear();

            this.TableLayoutPanel.ColumnCount = columnCount;
            this.TableLayoutPanel.RowCount    = rowCount;
            this.TableLayoutPanel.Size        = new Size(columnCount * pictureBoxControlTotalWidth, rowCount * pictureBoxControlTotalHeight);

            for (int x = 0; x < columnCount; x++)
            {
                // First add a column
                this.TableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));

                for (int y = 0; y < rowCount; y++)
                {
                    // Add a row
                    if (x == 0)
                    {
                        this.TableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                    }
                    PictureBoxControl pictureBoxControl = new PictureBoxControl();
                    pictureBoxControl.Location = new System.Drawing.Point(70, 120);
                    pictureBoxControl.PictureBox.SizeChanged += (sender, args) => OnImageChange(pictureBoxControl, args);
                    // When btn_AddToTrack is clicked, pass the PictureBoxControl to an event handler
                    pictureBoxControl.btn_AddToTrack.Click += (sender, args) => PictureBoxButton_Click(pictureBoxControl, args);
                    this.TableLayoutPanel.Controls.Add(pictureBoxControl, x, y);
                }
            }
        }
 // Event for adding image event to track
 private void PictureBoxButton_Click(Object sender, EventArgs args)
 {
     using (UndoBlock undo = new UndoBlock("Add media to track"))
     {
         try
         {
             PictureBoxControl PictureBoxControl = sender as PictureBoxControl;
             if (PictureBoxControl.PictureBox.ImageLocation is null)
             {
                 ;
             }
             else
             {
                 Timecode cursorPosition = this.myVegas.Transport.CursorPosition;
                 this.myVegas.SelectionStart = cursorPosition;
                 VideoEvent videoEvent = (VideoEvent)AddMedia(this.myVegas.Project, PictureBoxControl.PictureBox.ImageLocation, animationTrack, cursorPosition, Timecode.FromFrames(300));
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }