/**
         * Event handler that toggles the buttons.
         */
        public void LightUp(object sender, EventArgs e)
        {
            LightButton b = (LightButton)sender;

            //Lights up the button clicked.
            b.changeLight();
            //Lights up the button on the left if there is one.
            if (b.TabIndex - 1 >= 0 && b.TabIndex - 5 != 0 && b.TabIndex - 5 != 5 && b.TabIndex - 5 != 10 && b.TabIndex - 5 != 15)
            {
                LightButton left = (LightButton)grid.GetControlFromPosition(grid.GetColumn(b) - 1, grid.GetRow(b));
                left.changeLight();
            }
            //Lights up the button on the right if there is one.
            if (b.TabIndex + 1 <= 24 && b.TabIndex + 1 != 5 && b.TabIndex + 1 != 10 && b.TabIndex + 1 != 15 && b.TabIndex + 1 != 20)
            {
                LightButton right = (LightButton)grid.GetControlFromPosition(grid.GetColumn(b) + 1, grid.GetRow(b));
                right.changeLight();
            }
            //Lights up the button on bottom if there is one
            if (b.TabIndex + 5 <= 24)
            {
                LightButton bottom = (LightButton)grid.GetControlFromPosition(grid.GetColumn(b), grid.GetRow(b) + 1);
                bottom.changeLight();
            }
            //Lights up the button on top if there is one.
            if (b.TabIndex - 5 >= 0)
            {
                LightButton top = (LightButton)grid.GetControlFromPosition(grid.GetColumn(b), grid.GetRow(b) - 1);
                top.changeLight();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < InfoTable2.ColumnCount; i++)
            {
                var control = InfoTable2.GetControlFromPosition(i, 0);
                InfoTable2.Controls.Remove(control);
            }
            Project.Instance.removeLastEffort();

            for (int i = 1; i < InfoTable2.RowCount; i++)
            {
                for (int k = 0; k < InfoTable2.ColumnCount; k++)
                {
                    var control = InfoTable2.GetControlFromPosition(k, i);
                    if (control != null)
                    {
                        InfoTable2.SetRow(control, i - 1);
                    }
                }
            }


            int[] temp = Project.Instance.getHours();
            updatePieChart(temp[0], temp[1], temp[2], temp[3], temp[4]);
            ProjectEffortManagement.Instance.totalLabel.Text = temp[5].ToString();

            InfoTable2.RowCount--;
            warningLabel.Text = "";

            if (pj.EffortListCount == 0)
            {
                button2.Enabled = false;
            }
            Project.Instance.RewriteFile();
        }
예제 #3
0
        private Button MakeRemoveButton()
        {
            Button button = new Button();

            button.Text = "X";

            button.Click += delegate
            {
                IsDeleted = true;
                int index = Index;
                for (int i = 0; i < _parentPanel.ColumnCount; i++)
                {
                    _parentPanel.GetControlFromPosition(i, index).Dispose();
                }
                Console.WriteLine("Clicked row " + index);

                //Move all additional rows up
                for (int row = index; row < _parentPanel.RowCount - 1; row++)
                {
                    Console.WriteLine("Processing row " + row);
                    for (int col = 0; col < _parentPanel.ColumnCount; col++)
                    {
                        _parentPanel.SetRow(_parentPanel.GetControlFromPosition(col, row + 1), row);
                    }
                }

                _parentPanel.RowCount--;
            };

            return((Button)ProcessControl(button));
        }
예제 #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     try {
         string strCommand = "";
         int    i          = 1;
         foreach (var item in groupbox)
         {
             TableLayoutPanel layoutPanel = (TableLayoutPanel)item.Value.Controls.Container;
             ComboBox         comboxCol   = (ComboBox)layoutPanel.GetControlFromPosition(0, 0);
             TextBox          textBox     = (TextBox)layoutPanel.GetControlFromPosition(1, 0);
             ComboBox         comboxAndOr = (ComboBox)layoutPanel.GetControlFromPosition(2, 0);
             if (i != groupbox.Count)
             {
                 strCommand += string.Format(" {0} like N'%{1}%' {2} ", comboxCol.SelectedValue, textBox.Text, comboxAndOr.SelectedValue);
             }
             else
             {
                 strCommand += string.Format(" {0} like N'%{1}%' ", comboxCol.SelectedValue, textBox.Text);
             }
         }
         strWhere          = string.Format(" where {0}", strCommand);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message, "button1_Click");
     }
 }
예제 #5
0
        private void LoadColors(XmlDocument doc, TableLayoutPanel tlp)
        {
            for (int i = 0; i <= tlp.RowCount; i++)
            {
                if (!(tlp.GetControlFromPosition(0, i) is Label lbl))
                {
                    continue;
                }

                var node = doc.SelectSingleNode($"//FontsAndColors//Categories/Category/Items/Item[@Name = '{lbl.Text}']");
                if (node == null)
                {
                    continue;
                }

                var fgAttribute = node.Attributes["Foreground"];
                if (tlp.GetControlFromPosition(1, i) is Label fgColor && fgAttribute != null)
                {
                    fgColor.BackColor = GetColor(fgAttribute.Value);
                    SetColorLabelToolTip(fgColor);
                    SetLabelImage(fgColor);
                }

                var bgAttribute = node.Attributes["Background"];
                if (tlp.GetControlFromPosition(3, i) is Label bgColor && bgAttribute != null)
                {
                    bgColor.BackColor = GetColor(bgAttribute.Value);
                    SetColorLabelToolTip(bgColor);
                    SetLabelImage(bgColor);
                }
            }
        }
예제 #6
0
 public void fillRoom(int targetLayer)
 {
     foreach (TextBox tb in TLPRoom.Controls)
     {
         tb.Enabled = true;
     }
     if (map.verticalHeights[map.currentRoomY] == 11)
     {
         for (int i = 0; i < 20; i++)
         {
             TLPRoom.GetControlFromPosition(i, 11).Enabled   = false;
             TLPRoom.GetControlFromPosition(i, 11).Text      = "0";
             TLPRoom.GetControlFromPosition(i, 11).BackColor = Color.SlateGray;
         }
     }
     if (map.verticalHeights[map.currentRoomY] == 8)
     {
         for (int i = 0; i < 20; i++)
         {
             for (int j = 0; j < 3; j++)
             {
                 TLPRoom.GetControlFromPosition(i, 9 + j).Enabled   = false;
                 TLPRoom.GetControlFromPosition(i, 9 + j).Text      = "0";
                 TLPRoom.GetControlFromPosition(i, 9 + j).BackColor = Color.SlateGray;
             }
         }
     }
     updateRoomGrid(targetLayer);
 }
 /// <summary>
 /// Load Collision IDs into Grid
 /// </summary>
 public void fillRoom()
 {
     UInt16[,] roomInfo = map.getRoomLayer(0);
     for (int i = 0; i < 20; i++)
     {
         for (int j = 0; j < map.verticalHeights[map.currentRoomY]; j++)
         {
             PictureBox pb = (PictureBox)TLPRoom.GetControlFromPosition(i, j);
             pb.Enabled = true;
             int   collisionIDHolder = roomInfo[i, j];
             Image imgHolder         = getCollisionByID(collisionIDHolder);
             pb.Image = imgHolder;
         }
     }
     if (map.verticalHeights[map.currentRoomY] < 12)
     {
         for (int i = 0; i < 20; i++)
         {
             for (int j = map.verticalHeights[map.currentRoomY]; j < 12; j++)
             {
                 PictureBox pb = (PictureBox)TLPRoom.GetControlFromPosition(i, j);
                 pb.Enabled = false;
                 pb.Image   = getCollisionByID(0);
             }
         }
     }
 }
예제 #8
0
        private List <string> getSelectedLogs()
        {
            List <string>    paths = new List <string>();
            TableLayoutPanel p;
            string           basePath = Utilities.ProgramFiles();

            if (logTabs.TabActive == HorizontalTabs.tabs.Tab1)
            {
                basePath += VIDEO_LOG_PATH;
                p         = videoLogPanel;
            }
            else
            {
                basePath += VIDEO_ERROR_LOG_PATH;
                p         = videoErrorLogPanel;
            }
            for (int i = 0; i < p.RowCount; i++)
            {
                TableLayoutPanel subPanel = p.GetControlFromPosition(0, i) as TableLayoutPanel;
                if ((subPanel.GetControlFromPosition(0, 0) as CheckBox_Square).Check)
                {
                    paths.Add(basePath + (subPanel.GetControlFromPosition(1, 0) as Label).Text);
                }
            }
            return(paths);
        }
        public static void PrintEnemyBoard(this Player p, TableLayoutPanel table)
        {
            WaterTile[,] board = p.PlayerBoard;
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(0); j++)
                {
                    switch (board[i, j].TileType)
                    {
                    case (TileType.Hit):
                        //Console.ForegroundColor = ConsoleColor.Red;
                        //Console.Write("|_X_|");
                        //Console.ResetColor();
                        table.GetControlFromPosition(j, i).BackColor = System.Drawing.Color.Red;
                        break;

                    case (TileType.Miss):
                        //Console.ForegroundColor = ConsoleColor.Gray;
                        //Console.Write("|_M_|");
                        //Console.ResetColor();
                        table.GetControlFromPosition(j, i).BackColor = System.Drawing.Color.GhostWhite;
                        break;

                    default:
                        table.GetControlFromPosition(j, i).BackColor = System.Drawing.Color.Transparent;
                        break;
                    }
                }
            }
        }
 private void AddRowHelper(TableLayoutPanel tlp, int idx, Func <int, Control> creatorFunc)
 {
     // add row
     tlp.RowCount++;
     tlp.RowStyles.Insert(idx, new RowStyle(SizeType.Absolute, GetRowHeight()));
     // shift right
     for (int r = tlp.RowCount; r > idx - 1; r--)
     {
         for (int c = 0; c < tlp.ColumnCount; c++)
         {
             var control = tlp.GetControlFromPosition(c, r);
             if (control != null)
             {
                 tlp.SetRow(control, r + 1);
             }
         }
     }
     // add controls
     for (int c = 0; c < tlp.ColumnCount; c++)
     {
         if (tlp.GetControlFromPosition(c, idx) == null)
         {
             tlp.Controls.Add(creatorFunc(c), c, idx);
         }
     }
 }
 private void AddColumnHelper(TableLayoutPanel tlp, int idx, Func <int, Control> creatorFunc)
 {
     // add column
     tlp.ColumnCount++;
     tlp.ColumnStyles.Insert(idx, new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
     // shift right
     for (int c = tlp.ColumnCount; c > idx - 1; c--)
     {
         for (int r = 0; r < tlp.RowCount; r++)
         {
             var control = tlp.GetControlFromPosition(c, r);
             if (control != null)
             {
                 tlp.SetColumn(control, c + 1);
             }
         }
     }
     // add controls
     for (int r = 0; r < tlp.RowCount; r++)
     {
         if (tlp.GetControlFromPosition(idx, r) == null)
         {
             tlp.Controls.Add(creatorFunc(r), idx, r);
         }
     }
 }
예제 #12
0
        public virtual TableLayoutPanel Destroy()
        {
            for (int i = initialRow; i <= maxRow; i++)
            {
                Control c = table.GetControlFromPosition(0, i);

                if (c != null)
                {
                    table.Controls.Remove(c);
                }

                c = table.GetControlFromPosition(1, i);

                if (c != null)
                {
                    table.Controls.Remove(c);
                }
            }

            if (endLabel != null)
            {
                table.Controls.Remove(endLabel);
            }

            return(table);
        }
예제 #13
0
        public void setLabelsFromArray(int[,] array, TableLayoutPanel tableLayoutPanel)
        {
            int rows = array.GetUpperBound(0) + 1;
            int cols = array.Length / rows;

            for (int i = 0; i < rows - 2; i++)
            {
                for (int j = 0; j < cols - 2; j++)
                {
                    if (array[i + 1, j + 1] == 0)
                    {
                        //tableLayoutPanel1.GetControlFromPosition(j, i).BackColor = Color.Gray;
                        tableLayoutPanel.GetControlFromPosition(j, i).BackgroundImage = grayImage;
                    }

                    if (array[i + 1, j + 1] == 1)
                    {
                        tableLayoutPanel.GetControlFromPosition(j, i).BackColor = Color.DarkCyan;
                    }
                    if (array[i + 1, j + 1] == 3)
                    {
                        //  tableLayoutPanel1.GetControlFromPosition(j, i).BackColor = Color.OrangeRed;
                        tableLayoutPanel.GetControlFromPosition(j, i).BackgroundImage = orangeImage;
                    }

                    if (array[i + 1, j + 1] == 2)
                    {
                        // tableLayoutPanel1.GetControlFromPosition(j, i).BackColor = Color.Red;
                        tableLayoutPanel.GetControlFromPosition(j, i).BackgroundImage = redImage;
                    }
                }
            }
        }
예제 #14
0
        private Form1.Team[] CheckNewTeams(TableLayoutPanel tableLayout, bool bonus)
        {
            List <Form1.Team> teams_list = new List <Form1.Team>();

            //Обнуление бонусных очков за прошлый сезон
            Form1.Team t;
            for (int i = 0; i < m_MainForm.m_TeamsAll.Count; i++)
            {
                t = m_MainForm.m_TeamsAll[i];
                t.c_bonus_score          = 0;
                m_MainForm.m_TeamsAll[i] = t;
            }


            for (int i = 0; i < tableLayout.RowCount - 1; i++)
            {
                if (tableLayout.GetControlFromPosition(2, i + 1).Text == "")
                {
                    continue;
                }
                bool is_contains = false;
                for (int j = 0; j < m_MainForm.m_TeamsAll.Count; j++)
                {
                    if (tableLayout.GetControlFromPosition(1, i + 1).Text == m_MainForm.m_TeamsAll[j].c_owner && tableLayout.GetControlFromPosition(2, i + 1).Text == m_MainForm.m_TeamsAll[j].c_name)
                    {
                        teams_list.Add(m_MainForm.m_TeamsAll[j]);
                        is_contains = true;
                        break;
                    }
                }

                if (!is_contains)
                {
                    teams_list.Add(CreateNewTeam(tableLayout.GetControlFromPosition(1, i + 1).Text, tableLayout.GetControlFromPosition(2, i + 1).Text, m_MainForm.m_TeamsAll[m_MainForm.m_TeamsAll.Count - 1].c_id + 1));
                    m_MainForm.m_TeamsAll.Add(teams_list[teams_list.Count - 1]);
                }

                if (i < 3)
                {
                    Form1.Team tt = teams_list[teams_list.Count - 1];
                    tt.c_bonus_score = 1;
                    teams_list[teams_list.Count - 1] = tt;
                }

                else if (i >= tableLayout.RowCount - 4)
                {
                    Form1.Team tt = teams_list[teams_list.Count - 1];
                    tt.c_bonus_score = -1;
                    teams_list[teams_list.Count - 1] = tt;
                }
                else
                {
                    Form1.Team tt = teams_list[teams_list.Count - 1];
                    tt.c_bonus_score = 0;
                    teams_list[teams_list.Count - 1] = tt;
                }
            }
            Form1.Team[] new_teams = teams_list.ToArray();
            return(new_teams);
        }
예제 #15
0
        private void removeRow(ref TableLayoutPanel TLP, bool relayout)
        {
            int bottomTimerIndex = returnTmrCnt() - 1;// -1 is to get to active's zero index.

            if (!timerCanBeRemoved())
            {
                return;
            }
            if (bottomTimerIndex == TIMEENGINE.getActiveRow())
            {
                TIMEENGINE.changeActive(-1);              // If the active row is to be removed stop.
            }
            TIMEENGINE.resetTimerValue(bottomTimerIndex); // make sure the removed value is zero. It might not be.
            disUpdTotal(TIMEENGINE.engCalcArrayTotal());  // if you removed an existing row you want to reset the total.

            int bottomRowIndex = baseTLP.RowCount - 1;

            TLP.SuspendLayout();
            Control c = TLP.GetControlFromPosition(0, bottomRowIndex);

            TLP.Controls.Remove(c);
            c.Dispose();
            Control d = TLP.GetControlFromPosition(2, bottomRowIndex);

            TLP.Controls.Remove(d);
            d.Dispose();
            Control e = TLP.GetControlFromPosition(3, bottomRowIndex);

            TLP.Controls.Remove(e);
            e.Dispose();
            TLP.RowStyles.RemoveAt(bottomRowIndex);
            TLP.RowCount--;
            TLP.ResumeLayout(false);
            TLP.PerformLayout();
        }
예제 #16
0
        private void AddCssStyles(StringBuilder sb, TableLayoutPanel tlp)
        {
            for (int i = 0; i <= tlp.RowCount; i++)
            {
                if (!(tlp.GetControlFromPosition(0, i) is Label lbl) ||
                    lbl.Text == "Plain Text" ||
                    lbl.Text == "Selected Text")
                {
                    continue;
                }

                var fgColor = tlp.GetControlFromPosition(1, i) as Label;
                var bgColor = tlp.GetControlFromPosition(3, i) as Label;

                if ((fgColor != null && fgColor.BackColor != Color.Transparent) ||
                    (bgColor != null && bgColor.BackColor != Color.Transparent))
                {
                    var className = Regex.Replace(lbl.Text, @"[ \(\)/]", "");
                    sb.Append($".{className} {{");

                    if (fgColor != null)
                    {
                        sb.Append($" color:{ToCssHex(fgColor.BackColor)} !important;");
                    }
                    if (bgColor != null)
                    {
                        sb.Append($" background-color:{ToCssHex(bgColor.BackColor)} !important;");
                    }

                    sb.AppendLine("}");
                }
            }
        }
        public void remove_row(TableLayoutPanel panel, int row_index_to_remove)
        {
            if (row_index_to_remove >= panel.RowCount)
            {
                return;
            }

            // delete all controls of row that we want to delete
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                var control = panel.GetControlFromPosition(i, row_index_to_remove);
                panel.Controls.Remove(control);
            }

            // move up row controls that comes after row we want to remove
            for (int i = row_index_to_remove + 1; i < panel.RowCount; i++)
            {
                for (int j = 0; j < panel.ColumnCount; j++)
                {
                    var control = panel.GetControlFromPosition(j, i);
                    if (control != null)
                    {
                        panel.SetRow(control, i - 1);
                    }
                }
            }

            // remove last row
            panel.RowCount--;
        }
예제 #18
0
        public static void RemoveRow(TableLayoutPanel panel, int index)
        {
            if (index >= panel.RowCount)
            {
                return;
            }

            // delete all controls of row that we want to delete
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                var control = panel.GetControlFromPosition(i, index);
                panel.Controls.Remove(control);
            }

            // move up row controls that comes after row we want to remove
            for (int i = index + 1; i < panel.RowCount; i++)
            {
                for (int j = 0; j < panel.ColumnCount; j++)
                {
                    var control = panel.GetControlFromPosition(j, i);
                    if (control != null)
                    {
                        panel.SetRow(control, i - 1);
                    }
                }
            }
        }
예제 #19
0
        public static void DoCompare(TableLayoutPanel Table, TableLayoutPanel Base)
        {
            if (smallerIsBetter.Count == 0 || biggerIsBetter.Count == 0)
            {
                PrepareLists();
            }
            for (var row = 0; row < Table.RowCount; row++)
            {
                Control label = Table.GetControlFromPosition(0, row);
                Control value = Table.GetControlFromPosition(1, row);
                if (!value.Text.Equals(label.Text))
                {
                    bool found = false;
                    for (var brow = 0; brow < Base.RowCount; brow++)
                    {
                        Control blabel    = Base.GetControlFromPosition(0, brow);
                        Control BaseValue = Base.GetControlFromPosition(1, brow);

                        if (blabel.Text.Equals(label.Text) && ((value.Tag != null && value.Tag.Equals(BaseValue.Tag)) || value.Tag == null))
                        {
                            value.BackColor = GetBackgroundColor(label, value, BaseValue);
                            found           = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        value.BackColor = Color.LightYellow;
                    }
                }
            }
        }
예제 #20
0
        void GameOver()
        {
            timer.Stop();
            for (int column = 1; column < width + 1; column++)
            {
                for (int row = 1; row < height + 1; row++)
                {
                    table.GetControlFromPosition(column, row).Enabled = false;
                }
            }
            var result = MessageBox.Show($"Ваш результат: {score}\nХотите начать заново?", "", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                timer.Stop();
                time           = 10;
                label.Text     = "10";
                timer.Interval = 1000;
                difficult      = 0;
                score          = 0;
                Controls.Remove(table);
                StartGame();
            }
            else
            {
                isUsualExit = false;
                Close();
            }
        }
예제 #21
0
        private void ShipDragDrop(TableLayoutPanel t_myships, int shipcount, object sender, DragEventArgs e)
        {
            var cellPos = GetRowColIndex(t_myships, t_myships.PointToClient(Cursor.Position));

            if (cellPos == null)//out of range
            {
                MessageBox.Show("out of range");
                return;
            }
            if (shipcount == 1)
            {
                if (shipCount1[ship_lg - 1] == 1)
                {
                    MessageBox.Show("Ship already used!");
                    return;
                }
            }
            else
            {
                if (shipCount2[ship_lg - 1] == 1)
                {
                    MessageBox.Show("Ship already used!");
                    return;
                }
            }
            if (cellPos != null && inBound(cellPos, ship_lg, direc) && CheckShipLoc(t_myships, cellPos, ship_lg, direc))
            {
                if (direc == "" || direc == "right")
                {
                    for (int r = 0; r < ship_lg; r++)
                    {
                        Button b = (Button)t_myships.GetControlFromPosition(cellPos.Value.X + r, cellPos.Value.Y);
                        b.Text = "O";
                    }
                }
                else
                {
                    for (int r = 0; r < ship_lg; r++)
                    {
                        Button b = (Button)t_myships.GetControlFromPosition(cellPos.Value.X, cellPos.Value.Y + r);
                        b.Text = "O";
                    }
                }

                //TO DO :SAVE TO LOC ARRAY
                if (shipcount == 1)
                {
                    shipCount1[ship_lg - 1] = 1;
                }
                else
                {
                    shipCount2[ship_lg - 1] = 1;
                }
                //TO DO : REMOVE ITEM FROM LIST
            }
            else
            {
                MessageBox.Show("relocate ship");
            }
        }
예제 #22
0
        private void FillTable(List <Team> teams, TableLayoutPanel table)
        {
            for (int i = 0; i < teams.Count; i++)
            {
                var team       = teams[i];
                var teamButton = new Button
                {
                    Text              = team.Name,
                    Image             = team.Flag,
                    TextImageRelation = TextImageRelation.ImageBeforeText,
                    Padding           = new Padding(13),
                    Dock              = DockStyle.Fill,
                    FlatStyle         = FlatStyle.Flat,
                    Font              = new Font("Bold", 13),
                };
                teamButton.FlatAppearance.BorderSize = 0;

                table.Controls.Add(teamButton);
                table.SetColumn(teamButton, 1);
                table.SetRow(teamButton, i + 1);

                table.GetControlFromPosition(2, i + 1).Text = team.W.ToString();
                table.GetControlFromPosition(3, i + 1).Text = team.D.ToString();
                table.GetControlFromPosition(4, i + 1).Text = team.L.ToString();
                table.GetControlFromPosition(5, i + 1).Text = team.Points.ToString();
                table.GetControlFromPosition(6, i + 1).Text = team.PlusMinus.ToString();
            }
        }
예제 #23
0
        private void PopRowFromTable(TableLayoutPanel table)
        {
            // Clear prev last row from table
            for (int i = 0; i < table.ColumnCount; i++)
            {
                Control control = table.GetControlFromPosition(i, table.RowCount - 2);
                if (control != null)
                {
                    table.Controls.Remove(control);
                }
            }

            // Move last row upward
            for (int i = 0; i < table.ColumnCount; i++)
            {
                Control control = table.GetControlFromPosition(i, table.RowCount - 1);
                if (control != null)
                {
                    table.Controls.Remove(control);
                    table.Controls.Add(control, i, table.RowCount - 2);
                }
            }

            table.RowCount -= 1;
        }
    public static void RemoveArbitraryRow(TableLayoutPanel panel, int rowIndex)
    {
        if (rowIndex >= panel.RowCount)
        {
            return;
        }
        // delete all controls of row that we want to delete
        for (int i = 0; i < panel.ColumnCount; i++)
        {
            var control = panel.GetControlFromPosition(i, rowIndex);
            panel.Controls.Remove(control);
        }
        // move up row controls that comes after row we want to remove
        for (int i = rowIndex + 1; i < panel.RowCount; i++)
        {
            for (int j = 0; j < panel.ColumnCount; j++)
            {
                var control = panel.GetControlFromPosition(j, i);
                if (control != null)
                {
                    panel.SetRow(control, i - 1);
                }
            }
        }
        var removeStyle = panel.RowCount - 1;

        if (panel.RowStyles.Count > removeStyle)
        {
            panel.RowStyles.RemoveAt(removeStyle);
        }
        panel.RowCount--;
    }
예제 #25
0
        public static void RemoveRow(this TableLayoutPanel panel, int rowIndexToRemove)
        {
            if (rowIndexToRemove >= panel.RowCount)
            {
                return;
            }

            // delete all controls of row that we want to delete
            for (var i = 0; i < panel.ColumnCount; i++)
            {
                var control = panel.GetControlFromPosition(i, rowIndexToRemove);
                panel.Controls.Remove(control);
            }

            // move up row controls that comes after row we want to remove
            for (var i = rowIndexToRemove + 1; i < panel.RowCount; i++)
            {
                for (var j = 0; j < panel.ColumnCount; j++)
                {
                    var control = panel.GetControlFromPosition(j, i);
                    if (control != null)
                    {
                        panel.SetRow(control, i - 1);
                    }
                }
            }

            // remove last row
            panel.RowStyles.RemoveAt(panel.RowCount - 1);
            panel.RowCount--;
        }
예제 #26
0
 /// <summary>
 /// This method is responsible for editing a recod in the GUI
 /// </summary>
 /// <param name="table">A Table Layout Panel you want to add a new record to.</param>
 /// <param name="rowIndex">The row index where you want to add the new record.</param>
 /// <param name="salesRecord">The sales record that you are editting.</param>
 /// <param name="productRecord">The corresponding ProductRecord for the SalesRecord.</param>
 static public void editRecord(TableLayoutPanel table, int rowIndex, SalesRecord salesRecord, ProductRecord productRecord)
 {
     // Modifying the text within the labels for the SalesRecord
     table.GetControlFromPosition(1, rowIndex).Text = productRecord.Name;
     table.GetControlFromPosition(2, rowIndex).Text = salesRecord.DateSold.ToString();
     table.GetControlFromPosition(3, rowIndex).Text = salesRecord.Quantity.ToString();
     table.GetControlFromPosition(4, rowIndex).Text = "$" + (productRecord.Price * salesRecord.Quantity).ToString();
 }
예제 #27
0
        //
        // The next functions are rank-specific
        //
        //
        // Pawn
        //
        static private List <Point> CalcPawn(ChessPiece piece, TableLayoutPanel board)
        {
            //
            // Vars
            //
            List <Point> result = new List <Point>();
            int          offset = piece.isWhite ? -1 : 1;
            TableLayoutPanelCellPosition pos = board.GetPositionFromControl(piece.box);
            int row = pos.Row;
            int col = pos.Column;

            //
            // Straight move
            //
            if ((PictureBox)board.GetControlFromPosition(col, row + offset) == null)
            {
                result.Add(new Point(col, row + offset));
            }
            if (piece.canDouble && (PictureBox)board.GetControlFromPosition(col, row + (2 * offset)) == null)
            {
                result.Add(new Point(col, row + (2 * offset)));
            }

            for (int x = 1; x >= -1; x -= 2)
            {
                if ((x == -1 && col == 0) ||
                    (x == 1 && col == 7))
                {
                    continue;
                }
                //
                // Diag attacks
                //
                PictureBox pbox = (PictureBox)board.GetControlFromPosition(col + x, row + offset);
                if (pbox != null)
                {
                    ChessPiece ppiece = CheckPiece(pbox);
                    if (ppiece.isWhite != piece.isWhite)
                    {
                        result.Add(new Point(col + x, row + offset));
                    }
                }
                //
                // En Passant
                //
                pbox = (PictureBox)board.GetControlFromPosition(col + x, row);
                if (pbox != null)
                {
                    ChessPiece ppiece = CheckPiece(pbox);
                    if ((ppiece.isWhite != piece.isWhite) && ppiece.PassElig)
                    {
                        result.Add(new Point(col + x, row + offset));
                    }
                }
            }

            return(result);
        }
예제 #28
0
 /// <summary>
 /// This method is responsible for changing the background color of a row.
 /// </summary>
 /// <param name="table">A table layout panel where you want to change the color of a row.</param>
 /// <param name="rowIndex">The row index where you want to add the new record.</param>
 /// <param name="backColor">The color you want to make the row.</param>
 static public void setRowBackground(TableLayoutPanel table, int rowIndex, Color backColor)
 {
     // Changing the background color of the labels in a row
     table.GetControlFromPosition(0, rowIndex).BackColor = backColor;
     table.GetControlFromPosition(1, rowIndex).BackColor = backColor;
     table.GetControlFromPosition(2, rowIndex).BackColor = backColor;
     table.GetControlFromPosition(3, rowIndex).BackColor = backColor;
     table.GetControlFromPosition(4, rowIndex).BackColor = backColor;
 }
예제 #29
0
        public void UpdateForm()
        {
            foreach (var label in AmountOfShipsLabels)
            {
                label.Value.Text = Setup.AmountOfShips[label.Key].ToString();
            }
            bool isCompleted = true;

            foreach (var shipType in Setup.AmountOfShips)
            {
                if (shipType.Value != 0)
                {
                    isCompleted = false;
                }
            }
            if (isCompleted)
            {
                FinishButton.BackColor = Color.LightGreen;
                FinishButton.Enabled   = true;
            }
            else
            {
                FinishButton.BackColor = Color.LightGray;
                FinishButton.Enabled   = false;
            }
            foreach (var ship in Setup.ActiveShip)
            {
                if (ship.Value)
                {
                    ((Button)Ships.GetControlFromPosition(0, ship.Key - 1)).BackColor = Color.Green;
                }
                else
                {
                    ((Button)Ships.GetControlFromPosition(0, ship.Key - 1)).BackColor = Color.LightGray;
                }
            }
            for (int column = 0; column < ModelGame.Size; column++)
            {
                for (int row = 0; row < ModelGame.Size; row++)
                {
                    switch (Game.FirstPlayer.Map.Location[column, row])
                    {
                    case State.Ship:
                        ((Button)PlayerField.GetControlFromPosition(column, row)).BackColor = Color.Green;
                        break;

                    case State.NearShip:
                        ((Button)PlayerField.GetControlFromPosition(column, row)).BackColor = Color.LightGray;
                        break;

                    case State.Empty:
                        ((Button)PlayerField.GetControlFromPosition(column, row)).BackColor = Color.White;
                        break;
                    }
                }
            }
        }
예제 #30
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            string text = "";

            if (!tb_Repassword.Text.Equals(tb_password.Text))
            {
                text += "請確認密碼\n";
            }
            if (!"".Equals(text))
            {
                AutoClosingMessageBox.Show(text);
                return;
            }
            string[,] strFieldArray = new string[5, 2]
            {
                {
                    "Password",
                    tb_password.Text
                },
                {
                    "Name",
                    tb_Name.Text
                },
                {
                    "Email",
                    tb_email.Text
                },
                {
                    "Type",
                    (cb_type.SelectedItem as ComboboxItem).Value.ToString()
                },
                {
                    "Status",
                    (cb_status.SelectedItem as ComboboxItem).Value.ToString()
                }
            };
            DataBaseUtilities.DBOperation(Program.ConnectionString, TableOperation.Update, "", "hypos_User", "Account = {0}", "", strFieldArray, new string[1]
            {
                l_account.Text
            }, CommandOperationType.ExecuteNonQuery);
            TableLayoutPanel tlp_userManage = (base.Owner as frmSystemSetup).tlp_userManage;

            for (int i = 1; i < tlp_userManage.RowCount; i++)
            {
                Label label = (Label)tlp_userManage.GetControlFromPosition(1, i);
                if (l_account.Text.Equals(label.Text))
                {
                    (tlp_userManage.GetControlFromPosition(2, i) as Label).Text = tb_Name.Text;
                    (tlp_userManage.GetControlFromPosition(3, i) as Label).Text = (cb_type.SelectedItem as ComboboxItem).Text;
                    (tlp_userManage.GetControlFromPosition(4, i) as Label).Text = (cb_status.SelectedItem as ComboboxItem).Text;
                    break;
                }
            }
            AutoClosingMessageBox.Show("已變更");
            Close();
        }