Пример #1
0
        // create matrix
        public void CreateSquare(int size, int[,] res)
        {
            var panel = new TableLayoutPanel();

            panel.RowCount    = size;
            panel.ColumnCount = size;
            panel.BackColor   = Color.Gray;
            panel.Location    = new Point(0, 40);


            this.Controls.Add(panel);


            for (int i = 0; i < size; i++)
            {
                var percent = 100f / (float)size;
                panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, percent));
                panel.RowStyles.Add(new RowStyle(SizeType.Percent, percent));
            }


            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    var button = new Button();

                    if (res[i, j] == 1)
                    {
                        button.Text = "1";

                        button.BackColor = Color.HotPink;
                    }
                    if (res[i, j] == 2)
                    {
                        button.BackColor = Color.Snow;
                        button.Text      = "2";
                        button.ForeColor = Color.Black;
                    }
                    if (res[i, j] == 3)
                    {
                        button.BackColor = Color.CornflowerBlue;
                        button.Text      = "3";
                        button.ForeColor = Color.Black;
                    }
                    if (res[i, j] == 4)
                    {
                        button.BackColor = Color.Plum;
                        button.Text      = "4";
                        button.ForeColor = Color.Black;
                    }
                    if (res[i, j] == 5)
                    {
                        button.BackColor = Color.DarkGoldenrod;
                        button.Text      = "5";
                        button.ForeColor = Color.Black;
                    }


                    button.Font      = new Font(button.Font.FontFamily, 20, FontStyle.Bold);
                    button.FlatStyle = FlatStyle.Flat;


                    button.Text = string.Format("{0}", (i) * size + j + 1);
                    button.Name = string.Format("Button{0}", button.Text);
                    button.Dock = DockStyle.Fill;


                    panel.Controls.Add(button, j, i);
                }
            }



            panel.SetBounds(x, y, 100, 100);
            if (x < 100)
            {
                protectMem p = new protectMem();
                p.enter();
                prev_y = y;
                y     += 130;

                p.leave();
            }
        }
Пример #2
0
        // write state
        public void WriteState(int size, String[] stateShape)
        {
            var panel = new TableLayoutPanel();

            panel.RowCount  = size;
            panel.BackColor = Color.Gray;


            this.Controls.Add(panel);


            for (int i = 0; i < size; i++)
            {
                var percent = 100f / (float)size;
                panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, percent));
                panel.RowStyles.Add(new RowStyle(SizeType.Percent, percent));
            }

            for (int i = 0; i < size; i++)
            {
                var state = new Label();
                state.Text = stateShape[i];
                string[] value = stateShape[i].Split();
                //  state.BackColor = Color.Beige;
                //  state.BackColor = Color.GhostWhite;
                //state.BackColor = Color.MistyRose;
                state.BackColor = Color.LightGray;
                Console.WriteLine(stateShape[i]);
                state.Font = new Font(state.Font.FontFamily, 9, FontStyle.Bold);
                switch (value[0])
                {
                case "1":
                    state.ForeColor = Color.HotPink;
                    break;

                case "2":
                    state.ForeColor = Color.Snow;
                    break;

                case "3":
                    state.ForeColor = Color.CornflowerBlue;
                    break;

                case "4":
                    state.ForeColor = Color.DarkOrchid;
                    break;

                case "5":
                    state.ForeColor = Color.DarkGoldenrod;
                    break;
                }

                panel.Controls.Add(state, 0, i);
            }



            panel.SetBounds(x + 250, prev_y, 100, 100);
            if (x < 100)
            {
                protectMem p = new protectMem();
                p.enter();
                prev_y = y;
                p.leave();
            }
        }