//CONSTRUCTOR: generates the Form
        public Form1()
        {
            //Initializes the Form and its Components
            InitializeComponent();

            //Opens with an Example
            NewTab(6, 6, "new Grid");

            selectedTab = (GridTab)tabControl1.SelectedTab;
        }
        //Event is called when the User changes Tabs
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //chacks if any tabs exist
            if (tabControl1.SelectedIndex >= 0)
            {
                //updates the selected Tab as it changed
                selectedTab = (GridTab)this.tabControl1.SelectedTab;

                //Updates the size of the GridDrawing of the newly selectedTab as it might have changed while the tab was not active
                selectedTab.gd.SetSize(selectedTab.border, selectedTab.border, selectedTab.Width - selectedTab.border * 3, selectedTab.Height - selectedTab.border * 3);

                //Updats the trackBraGen to the Values of the new Tab
                this.trackBarGen.Maximum = selectedTab.grid.generation;
                this.trackBarGen.Value   = selectedTab.fieldIndex + 1;

                //Refreshes the Drawing
                this.selectedTab.Invalidate();
            }
        }
        //FUNCTIONS THAT AREN'T EVENTS

        //Creates a new GridTab
        public void NewTab(int width, int height, string tabName)
        {
            //Makes a new GridTab with given width, height and name
            GridTab t = new GridTab(this, new Grid(width, height), 20, tabName);

            //added the new Tab to the tabControl
            this.tabControl1.TabPages.Add(t);

            //added Paint and MouseClick Events to the Tab
            t.Paint     += new PaintEventHandler(Tab_Paint);
            t.MouseDown += new MouseEventHandler(Tab_MouseClick);

            //sets the size of the gridDrawing of the new Tab
            t.gd.SetSize(t.border, t.border, t.Width - t.border * 2, t.Height - t.border * 2);

            //maks selectedTab to the new Tab
            this.selectedTab = t;

            //Selects the new Tab in the tabControl
            this.tabControl1.SelectedTab = t;
        }