public void TableLayoutPanel_GetPositionFromControl_ControlExists_ReturnsExpected(int columnSpan, int rowSpan)
        {
            var control = new ScrollableControl
            {
                Visible = true
            };
            var panel = new TableLayoutPanel();

            panel.Controls.Add(control);
            panel.SetColumn(control, 1);
            panel.SetRow(control, 2);
            panel.SetColumnSpan(control, columnSpan);
            panel.SetRowSpan(control, rowSpan);

            Assert.Equal(new TableLayoutPanelCellPosition(1, 2), panel.GetPositionFromControl(control));
        }
Esempio n. 2
0
        internal void CheckPromote(TableLayoutPanel board)
        {
            if (pieceRank != 0)
            {
                return;
            }
            TableLayoutPanelCellPosition boxpos = board.GetPositionFromControl(box);

            if (isWhite && boxpos.Row == 0)
            {
                PromotePawn();
            }
            else if (!isWhite && boxpos.Row == 7)
            {
                PromotePawn();
            }
        }
        private void CalcTotals(object tb)
        {
            int numberOfRows    = tableLayoutPanelAA.RowCount - 1;
            int numberOfColumns = tableLayoutPanelAA.ColumnCount - 1;
            TableLayoutPanelCellPosition position = tableLayoutPanelAA.GetPositionFromControl(tb as FlowLayoutPanel);
            Label  totalAssetClass = tableLayoutPanelAA.GetControlFromPosition(position.Column, numberOfRows) as Label;
            Label  totalCurrency   = tableLayoutPanelAA.GetControlFromPosition(numberOfColumns, position.Row) as Label;
            Label  total           = tableLayoutPanelAA.GetControlFromPosition(numberOfColumns, numberOfRows) as Label;
            double rowSum          = GetRowSum(position.Row);
            double columnSum       = GetColumnSum(position.Column);

            totalCurrency.Text   = rowSum.ToString();
            totalAssetClass.Text = columnSum.ToString();
            double totalSum = GetTotalSum();

            total.Text = totalSum.ToString();
        }
Esempio n. 4
0
 //_________________________Adding or Editing an item_________Form2___________________________________
 //Copies data of the item to Form2
 public static void EditLoad(bool isEdit, Control p, TableLayoutPanel descripTable, TextBox nameTb, TextBox priceTextBox, TextBox categoryTextBox, PictureBox picBoxPath, NumericUpDown quantityNumUpDown, TextBox picPathTb)
 {
     Form2.k                    = p.Name;
     isEdit                     = true;
     nameTb.Text                = p.Name;
     priceTextBox.Text          = items[p.Name].price.ToString();
     categoryTextBox.Text       = items[p.Name].category;
     picBoxPath.BackgroundImage = Image.FromFile(items[p.Name].PicPath);
     quantityNumUpDown.Value    = items[p.Name].quantity;
     picPathTb.Text             = items[p.Name].PicPath;
     string[] token = items[p.Name].description.Split('^');
     for (int i = 0; i < token.Length; i++)
     {
         string[] dtoken = token[i].Split('%');
         if (dtoken[0] != "")
         {
             descripTable.Visible = true;
             for (int j = 0; j < dtoken.Length; j++)
             {
                 TextBox tb = new TextBox();
                 tb.Text = dtoken[j];
                 tb.Size = new Size(203, 27);
                 tb.Font = new Font("Cambria", 14);
                 descripTable.Controls.Add(tb);
             }
             Button b = new Button();
             b.Text   = "X";
             b.Click += delegate
             {
                 Form2.rows--;
                 int cell = descripTable.GetPositionFromControl(b).Row;
                 for (int m = 0; m < descripTable.ColumnCount; m++)
                 {
                     descripTable.Controls.RemoveAt(cell);
                 }
                 if (!descripTable.HasChildren)
                 {
                     descripTable.Visible = false;
                 }
             };
             descripTable.Controls.Add(b);
             Form2.rows++;
         }
     }
 }
Esempio n. 5
0
        //
        // Knight
        //
        static private List <Point> CalcKnight(ChessPiece piece, TableLayoutPanel board)
        {
            TableLayoutPanelCellPosition pos = board.GetPositionFromControl(piece.box);
            int          y      = pos.Row;
            int          x      = pos.Column;
            List <Point> result = new List <Point>()
            {     // Calculate each point individually, TODO: optimise
                new Point(x + 1, y + 2),
                new Point(x - 1, y + 2),
                new Point(x + 1, y - 2),
                new Point(x - 1, y - 2),
                new Point(x + 2, y + 1),
                new Point(x - 2, y + 1),
                new Point(x + 2, y - 1),
                new Point(x - 2, y - 2)
            };

            return(result);
        }
Esempio n. 6
0
        //
        // Loop to calculate Diag/Lines
        //
        static private List <Point> LoopCalc(ChessPiece piece, TableLayoutPanel board, List <Dir> direction, int distance = 10)
        {
            List <Point> result = new List <Point>();
            TableLayoutPanelCellPosition pos = board.GetPositionFromControl(piece.box);
            int row     = pos.Row;
            int col     = pos.Column;
            int counter = 0;

            for (int[] xy = new int[2] {
                col, row
            }; LoopCheck(xy); xy = LoopFunc(xy, direction))
            {
                if (distance == counter++)
                {
                    break;
                }
                Point pt = new Point(xy[0], xy[1]);
                result.Add(pt);
                PictureBox box = (PictureBox)board.GetControlFromPosition(xy[0], xy[1]);
                if (box == null)
                {
                    result.Add(pt);
                }
                else
                {
                    if (box.Name == piece.box.Name)
                    {
                        continue;
                    }
                    if (CheckPiece(box).isWhite != piece.isWhite)
                    {
                        result.Add(pt);
                    }
                    break;
                }
            }
            return(result);
        }
        public static Size GetTableLayoutSize(TableLayoutPanel layoutPanel)
        {
            int[] rowHeights   = new int[100]; //this.RowCount];
            int[] columnWidths = new int[100]; //this.ColumnCount];
            foreach (Control subControl in layoutPanel.Controls)
            {
                var cell           = layoutPanel.GetPositionFromControl(subControl);
                var subControlSize = GetMinimumControlSize(subControl);

                Padding subControlMargin = subControl.Margin;
                int     width            = subControlSize.Width + subControlMargin.Horizontal;
                int     height           = subControlSize.Height + subControlMargin.Vertical;

                if (width > columnWidths[cell.Column])
                {
                    columnWidths[cell.Column] = width;
                }
                if (height > rowHeights[cell.Row])
                {
                    rowHeights[cell.Row] = height;
                }
            }

            // Note: Include System.Linq to get the Sum() function
            int totalWidth  = columnWidths.Sum();
            int totalHeight = rowHeights.Sum();

            var clientSize = new Size(totalWidth, totalHeight);

            // Add the padding to the client size
            clientSize = Size.Add(clientSize, new Size(layoutPanel.Padding.Horizontal, layoutPanel.Padding.Vertical));

            return(new Size(
                       Math.Max(clientSize.Width, layoutPanel.MinimumSize.Width),
                       Math.Max(clientSize.Height, layoutPanel.MinimumSize.Height)
                       ));
        }
Esempio n. 8
0
        public void TableLayoutPanel_GetPositionFromControl_NullControl_ReturnsExpected()
        {
            var panel = new TableLayoutPanel();

            Assert.Equal(new TableLayoutPanelCellPosition(-1, -1), panel.GetPositionFromControl(null));
        }
Esempio n. 9
0
        /// <summary>
        /// ЧТение дизайна блока из БД
        /// </summary>
        public static void ReadBlockDesign(Control block)
        {
            //Ищем родительскую форму/UserControl
            Control parent = block;

            while (!(parent is Form || parent is UserControl))
            {
                parent = parent.Parent;
            }


            //Размеры
            try
            {
                string width  = BlockDesignForm.SelectBlockParam("WIDTH", block, parent);
                string height = BlockDesignForm.SelectBlockParam("HEIGHT", block, parent);

                int Width  = Convert.ToInt32(width);
                int Height = Convert.ToInt32(height);


                //Ищем родительскую панель
                Control parent2 = block;
                while (!(parent2 is Panel || parent2 is TableLayoutPanel ||
                         parent2 is UserControl || parent2 is Form))
                {
                    parent2 = parent2.Parent;
                }



                //Применяем дизайн
                if (parent2 is TableLayoutPanel)
                {
                    try
                    {
                        //ТейблПанель, на которой дерево лежит
                        TableLayoutPanel             b   = (TableLayoutPanel)parent2;
                        TableLayoutPanelCellPosition pos = b.GetPositionFromControl(block);

                        //Применяем дизайн
                        b.ColumnStyles[pos.Column].Width = Width;
                        b.RowStyles[pos.Row].Height      = Height;
                    }
                    catch (Exception) { }
                }
                else
                {
                    try
                    {
                        parent2.Size = new Size(Width, Height);
                    }
                    catch (Exception) { }
                }
            }
            catch (Exception) { }

            //Соцсети
            if (block.Name == "SocialUC")
            {
                try
                {
                    UserControls.SocialUC social = (UserControls.SocialUC)block;

                    social.VKPictureBox.Visible = false;
                    string vk = BlockDesignForm.SelectBlockParam("VK", block, parent);
                    social.VKPictureBox.Visible = (vk == "1");

                    social.InstaPictureBox.Visible = false;
                    string insta = BlockDesignForm.SelectBlockParam("Insta", block, parent);
                    social.InstaPictureBox.Visible = (insta == "1");
                }
                catch (Exception) { }
            }
        }