Пример #1
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     Capture            = true;
     _lastKnownMousePos = e.Location;
     if (_vertical)
     {
         originalSizes = _viewsGrid.GetColumnWidths();
     }
     else
     {
         originalSizes = _viewsGrid.GetRowHeights();
     }
     base.OnMouseDown(e);
 }
Пример #2
0
        public void TableLayoutPanel_GetRowHeights_CustomStylesAbsoluteOverflow_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(70, 80)
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 100));
            Assert.Equal(new int[] { 100, 0 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 100));
            Assert.Equal(new int[] { 100, 100 }, panel.GetRowHeights());
        }
Пример #3
0
        Point?GetRowColIndex(TableLayoutPanel tlp, Point point)
        {
            if (point.X > tlp.Width || point.Y > tlp.Height)
            {
                return(null);
            }

            int w = tlp.Width;
            int h = tlp.Height;

            int[] widths = tlp.GetColumnWidths();

            int i;

            for (i = widths.Length - 1; i >= 0 && point.X < w; i--)
            {
                w -= widths[i];
            }
            int col = i + 1;

            int[] heights = tlp.GetRowHeights();
            for (i = heights.Length - 1; i >= 0 && point.Y < h; i--)
            {
                h -= heights[i];
            }

            int row = i + 1;

            return(new Point(col, row));
        }
Пример #4
0
        public int calculate(TableLayoutPanel panel, Label label, Point point, Point loc)
        {
            int number = -1;

            int panelWidth  = panel.Width;
            int panelHeight = panel.Height;

            int posPanelx1 = panel.Location.X;
            int posPanely1 = panel.Location.Y;

            int colWidth = panel.GetColumnWidths()[0];
            int rowWidth = panel.GetRowHeights()[0];

            int numb = panel.GetColumnWidths().Length;

            int x = point.X - loc.X - posPanelx1, y = point.Y - loc.Y - posPanely1;

            if (x >= panelWidth || y >= panelHeight)
            {
                Console.WriteLine(">");
                return(-1);
            }

            number = Convert.ToInt32((y / rowWidth - 1) * numb + x / colWidth);
            if (number < 0)
            {
                number = 0;
            }

            return(number);
        }
Пример #5
0
        public static int GetRowFromPoint(this TableLayoutPanel tableControl,
                                          System.Drawing.Point pt)
        {
            int[] rows = tableControl.GetRowHeights();
            //横列は気にしないnode
            //int[] cols = tableLayoutPanel1.GetColumnWidths();

            int row = -1;

            int bottom = 0;
            int top    = 0;

            int y = pt.Y;

            for (int n = 0; n < rows.Count(); n++)
            {
                if (n > 0)
                {
                    bottom += rows[n - 1];
                }
                top += rows[n];

                //                System.Diagnostics.Debug.WriteLine(string.Format("{0} < {1} < {2}", bottom, y, top));
                if (bottom <= y && y < top)
                {
                    row = n;
                    break;
                }
            }

            return(row);
        }
Пример #6
0
        //--------------------------------------------------------------------------
        // Given a point in a tlp, figure out what cell in that table layout was clicked.
        //--------------------------------------------------------------------------
        TableLayoutPanelCellPosition GetTableLayoutPanelRowColIndexFromPoint(TableLayoutPanel tlp, Point point)
        {
            // Adapted from http://stackoverflow.com/questions/15449504/how-do-i-determine-the-cell-being-clicked-on-in-a-tablelayoutpanel
            if (point.X > tlp.Width || point.Y > tlp.Height)
            {
                return(new TableLayoutPanelCellPosition(-1, -1));
            }

            int w = tlp.Width;
            int h = tlp.Height;

            int[] widths = tlp.GetColumnWidths();

            int i;

            for (i = widths.Length - 1; i >= 0 && point.X < w; i--)
            {
                w -= widths[i];
            }
            int col = i + 1;

            int[] heights = tlp.GetRowHeights();
            for (i = heights.Length - 1; i >= 0 && point.Y < h; i--)
            {
                h -= heights[i];
            }

            int row = i + 1;

            return(new TableLayoutPanelCellPosition(col, row));
        }
Пример #7
0
        public void TableLayoutPanel_GetRowHeights_CustomAbsoluteStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 10));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 5));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 6));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());
        }
Пример #8
0
        public void TableLayoutPanel_GetRowHeights_CustomInvalidStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(50, 50)
            };

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 22));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 22));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 6));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());
        }
Пример #9
0
        public void TableLayoutPanel_GetRowHeights_CustomPercentStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(70, 80)
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 20));
            Assert.Equal(new int[] { 80, 0 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 30));
            Assert.Equal(new int[] { 32, 48 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 6));
            Assert.Equal(new int[] { 32, 48 }, panel.GetRowHeights());
        }
Пример #10
0
        public void TableLayoutPanel_GetRowHeights_InvokeNoChildren_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle
            };

            Assert.Equal(new int[] { 0, 100 }, panel.GetRowHeights());
        }
Пример #11
0
        protected void ScaleToCell(Control control, TableLayoutPanel tableLayoutPanel, string text = null)
        {
            var rowHeights   = tableLayoutPanel.GetRowHeights();
            var columnWidths = tableLayoutPanel.GetColumnWidths();

            var position  = tableLayoutPanel.GetCellPosition(control);
            var rectangle = new Rectangle(0, 0, columnWidths[position.Column], rowHeights[position.Row]);

            rectangle.Width  = (int)(rectangle.Width * 0.9f);
            rectangle.Height = (int)(rectangle.Height * 0.9f);

            Scale(control, rectangle, text);
        }
Пример #12
0
        public DialogResult Prompt()
        {
            using (var f = new Form {
                StartPosition = FormStartPosition.CenterParent
            }) {
                layout.Controls.Add(new Label(), 1, layout.RowCount + 1);                 // prevent last control being aligned incorrectly
                layout.AutoScroll = true;

                var sc = new SplitContainer {
                    Dock = DockStyle.Fill, Orientation = Orientation.Horizontal
                };
                sc.Panel1.Controls.Add(layout);

                var ok = new Button {
                    Text = "OK", DialogResult = DialogResult.OK
                };
                f.AcceptButton = ok;
                ok.Click      += (o, e) => f.DialogResult = IsValid() ? DialogResult.OK : DialogResult.None;            // prevent form from closing if not valid

                var cancel = new Button {
                    Text = "Cancel", DialogResult = DialogResult.Cancel
                };
                f.CancelButton = cancel;

                var fl = new FlowLayoutPanel {
                    Dock = DockStyle.Right, WrapContents = false
                };
                fl.Controls.Add(ok);
                fl.Controls.Add(cancel);
                fl.Width      = ok.ClientSize.Width + cancel.ClientSize.Width + 20;
                sc.FixedPanel = FixedPanel.Panel2;
                sc.Panel2.Controls.Add(fl);

                f.ClientSize = new Size(f.ClientSize.Width, layout.GetRowHeights().Sum() + sc.Panel2.Height + 5);

                sc.IsSplitterFixed = true;
                f.Controls.Add(sc);

                var result = f.ShowDialog();
                if (result == DialogResult.OK)
                {
                    foreach (var ctrl in GetControls())
                    {
                        (ctrl.Tag as Action <bool>).Invoke(true);
                    }
                }

                return(result);
            }
        }
Пример #13
0
        //Helper Methods
        public Point GetIndex(TableLayoutPanel t, Point p)
        {
            int w = 0, h = 0;

            int[] widths = t.GetColumnWidths(), heights = t.GetRowHeights();
            int   i;

            for (i = 0; i < widths.Length && p.X > w; i++)
            {
                w += widths[i];
            }

            int col = i - 1;

            for (i = 0; i < heights.Length && p.Y + t.VerticalScroll.Value > h; i++)
            {
                h += heights[i];
            }

            int row = i - 1;

            return(new Point(col, row));
        }
Пример #14
0
        /// https://stackoverflow.com/questions/15449504/how-do-i-determine-the-cell-being-clicked-on-in-a-tablelayoutpanel
        /// https://www.codeproject.com/Questions/126882/How-can-I-know-the-clicked-cell-in-the-TableLayout
        private Point?GetRowColIndex(TableLayoutPanel tlp, int x, int y)
        {
            if (x > tlp.Width || y > tlp.Height || x < 0 || y < 0)
            {
                return(null);
            }
            int[] widths = tlp.GetColumnWidths();
            int   i      = widths.Length - 1;
            int   w      = tlp.Width - widths[i];

            while (i >= 0 && x < w)
            {
                w -= widths[--i];
            }
            int[] heights = tlp.GetRowHeights();
            int   j       = heights.Length - 1;
            int   h       = tlp.Height - heights[j];

            while (j >= 0 && y < h)
            {
                h -= heights[--j];
            }
            return(new Point(i, j));
        }
Пример #15
0
        public void TableLayoutPanel_GetRowHeights_NoRows_ReturnsExpectd()
        {
            var panel = new TableLayoutPanel();

            Assert.Empty(panel.GetRowHeights());
        }
Пример #16
0
        private void PopulateContainerBox(DataFilter dataFilter, List <List <KeyValuePair <string, int> > > containerBook, int pageIndex, TableLayoutPanel crumbTable, BreadCrumb crumb)
        {
            var firstColumnSize    = 0;
            var lastColumnSize     = 0;
            var largestDescription = 0;
            var dataSet            = containerBook[pageIndex];

            //clear current table and populate with the crumbs present in the current page
            crumbTable.Controls.Clear();
            for (var x = 0; x < dataSet.Count; x++)
            {
                var kvp   = dataSet[x];
                var arrow = new Label {
                    Text = ">", AutoSize = true, Margin = new Padding(0, 5, 0, 5)
                };
                crumbTable.Controls.Add(arrow, 0, x);
                if (arrow.Width > 0)
                {
                    firstColumnSize = arrow.Width;
                }

                var description = new Label {
                    Text = kvp.Key, AutoSize = true, Margin = new Padding(5)
                };
                crumbTable.Controls.Add(description, 1, x);
                if (description.Width > largestDescription)
                {
                    largestDescription = description.Width;
                }

                var deleteLink = new LinkLabel {
                    Text = "(x)", AutoSize = true, Margin = new Padding(0, 5, 0, 5)
                };
                deleteLink.Click += delegate
                {
                    var allGone = RemoveItemInContainer(dataFilter, kvp.Value);
                    _subItemPopup.Close();
                    if (allGone)
                    {
                        BreadCrumbClicked(crumb, new BreadCrumbClickedEventArgs(crumb));
                    }
                    else
                    {
                        BreadCrumbClicked(null, new BreadCrumbClickedEventArgs(null));
                        breadCrumbs_ListChanged(null, null);
                    }
                };
                crumbTable.Controls.Add(deleteLink, 2, x);
                if (deleteLink.Width > 0)
                {
                    lastColumnSize = deleteLink.Width;
                }
            }

            //if there exists more than one page add navigation row
            if (containerBook.Count > 1)
            {
                //forward and back buttons
                if (pageIndex > 0)
                {
                    var backButton = new Button {
                        Text = "<-", Size = new Size(30, 20)
                    };
                    backButton.Click += (x, y) =>
                    {
                        PopulateContainerBox(dataFilter, containerBook, pageIndex - 1,
                                             crumbTable, crumb);
                        if (_subItemPopup != null)
                        {
                            _subItemPopup.Size = _tableSize;
                        }
                    };
                    crumbTable.Controls.Add(backButton, 0, dataSet.Count);
                    if (backButton.Width > firstColumnSize)
                    {
                        firstColumnSize = backButton.Width;
                    }
                }
                if (pageIndex < containerBook.Count - 1)
                {
                    var forwardButton = new Button {
                        Text = "->", Size = new Size(30, 20)
                    };
                    forwardButton.Click += (x, y) =>
                    {
                        PopulateContainerBox(dataFilter, containerBook, pageIndex + 1,
                                             crumbTable, crumb);
                        if (_subItemPopup != null)
                        {
                            _subItemPopup.Size = _tableSize;
                        }
                    };
                    crumbTable.Controls.Add(forwardButton, 2, dataSet.Count);
                    if (forwardButton.Width > lastColumnSize)
                    {
                        lastColumnSize = forwardButton.Width;
                    }
                }

                //middle page reporting / goto page control
                var cellPanel = new Panel {
                    Size = new Size(largestDescription, 23)
                };
                var pageLabel = new Label {
                    Text = "Page ", AutoSize = true
                };
                pageLabel.Font = new Font(pageLabel.Font.ToString(), 10.0f);
                var pageSelectBox = new TextBox {
                    Text = (pageIndex + 1).ToString(), TextAlign = HorizontalAlignment.Center
                };
                pageSelectBox.KeyPress += (x, y) =>
                {
                    //if enter is pressed go to selected page (or reset to current page if no valid page is selected)
                    if (y.KeyChar == (char)13)
                    {
                        y.Handled = true;
                        int tempInt;
                        if (!int.TryParse(pageSelectBox.Text, out tempInt) ||
                            tempInt <= 0 || tempInt > containerBook.Count)
                        {
                            pageSelectBox.Text = (pageIndex + 1).ToString();
                        }
                        else
                        {
                            PopulateContainerBox(dataFilter, containerBook, tempInt - 1,
                                                 crumbTable, crumb);
                            if (_subItemPopup != null)
                            {
                                _subItemPopup.Size = _tableSize;
                            }
                        }
                    }
                };
                pageSelectBox.Leave += (x, y) => { pageSelectBox.Text = (pageIndex + 1).ToString(); };
                var totalLabel = new Label {
                    Text = " of " + containerBook.Count, AutoSize = true
                };
                totalLabel.Font = new Font(totalLabel.Font.ToString(), 10.0f);

                //add all three controls to the cell panel
                cellPanel.Controls.Add(pageLabel);
                cellPanel.Controls.Add(pageSelectBox);
                cellPanel.Controls.Add(totalLabel);

                //make sure boxes are wide enough
                pageSelectBox.Width = totalLabel.Width - 10;
                var totalCellWidth = pageLabel.Width + pageSelectBox.Width + totalLabel.Width;
                if (totalCellWidth > largestDescription)
                {
                    largestDescription = totalCellWidth;
                    cellPanel.Width    = totalCellWidth;
                }

                //reposition controls to final locations
                var startlocation = (largestDescription - totalCellWidth) / 2;
                pageLabel.Location     = new Point(startlocation, 0);
                pageSelectBox.Location = new Point(startlocation + pageLabel.Width, 0);
                totalLabel.Location    = new Point(startlocation + pageLabel.Width + pageSelectBox.Width, 0);
                crumbTable.Controls.Add(cellPanel, 1, dataSet.Count);
            }

            //Hack: sadly the obvious .GetRowHeights() and .getColumnWidths
            //dont give consistantly valid results, as such proper dimentions have
            //to be calculated as the table is formed.
            var rowHeights   = (crumbTable.GetRowHeights().Length) * 24;
            var columnWidths = firstColumnSize + lastColumnSize + 25 + largestDescription;

            _tableSize = new Size(columnWidths + 5, rowHeights + 5);
        }