Пример #1
0
        public void TableLayoutPanel_SetColumnSpan_MultipleTimes_GetReturnsExpected()
        {
            var control = new ScrollableControl();
            var panel   = new TableLayoutPanel();

            panel.SetColumnSpan(control, 1);
            Assert.Equal(1, panel.GetColumnSpan(control));

            panel.SetColumnSpan(control, 2);
            Assert.Equal(2, panel.GetColumnSpan(control));
        }
Пример #2
0
        public void TableLayoutPanel_GetColumnSpan_NoSuchControl_ReturnsExpected()
        {
            var control = new ScrollableControl();
            var panel   = new TableLayoutPanel();

            Assert.Equal(1, panel.GetColumnSpan(control));
        }
Пример #3
0
        public void TableLayoutPanel_SetColumnSpan_ValidControl_GetReturnsExpected(int value)
        {
            var control = new ScrollableControl();
            var panel   = new TableLayoutPanel();

            panel.SetColumnSpan(control, value);
            Assert.Equal(value, panel.GetColumnSpan(control));
        }
Пример #4
0
        protected LinkLabel ReplaceWithLinklable(Control ctl, string value)
        {
            LinkLabel r = null;

            if (ctl != null)
            {
                value       = (value == null ? string.Empty : value);
                r           = new LinkLabel();
                r.Name      = "lnk_" + ctl.Name;
                r.Location  = ctl.Location;
                r.Width     = ctl.Width;
                r.Margin    = ctl.Margin;
                r.Anchor    = ctl.Anchor;
                r.Dock      = ctl.Dock;
                r.Text      = value;
                r.TextAlign = ContentAlignment.MiddleLeft;
                r.Links.Add(0, value.Length, value);
                r.TabIndex = ctl.TabIndex;
                r.Tag      = ctl.Tag;
                r.Enter   += new EventHandler(OnControlEnter);
                r.Leave   += new EventHandler(OnControlLeave);

                Control          ctlParent = ctl.Parent;
                TableLayoutPanel tblParent = ctlParent as TableLayoutPanel;

                if (tblParent != null)
                {
                    TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl);
                    int colSpan = tblParent.GetColumnSpan(ctl);
                    tblParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    tblParent.Controls.Add(r, pos.Column, pos.Row);
                    tblParent.SetColumnSpan(r, colSpan);
                }
                else if (ctlParent != null)
                {
                    ctlParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    ctlParent.Controls.Add(r);
                }
            }
            return(r);
        }
Пример #5
0
        protected TextBox ReplaceWithTextbox(Control ctl, string value)
        {
            TextBox r = null;

            if (ctl != null)
            {
                r           = new TextBox();
                r.Name      = "txt_" + ctl.Name;
                r.ReadOnly  = true;
                r.BackColor = SystemColors.Window;
                r.Location  = ctl.Location;
                r.Width     = ctl.Width;
                r.Margin    = ctl.Margin;
                r.Anchor    = ctl.Anchor;
                r.Dock      = ctl.Dock;
                r.Text      = value;
                r.TabIndex  = ctl.TabIndex;
                r.Tag       = ctl.Tag;
                r.Enter    += new EventHandler(OnControlEnter);
                r.Leave    += new EventHandler(OnControlLeave);


                Control          ctlParent = ctl.Parent;
                TableLayoutPanel tblParent = ctlParent as TableLayoutPanel;
                if (tblParent != null)
                {
                    TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl);
                    int colSpan = tblParent.GetColumnSpan(ctl);
                    tblParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    tblParent.Controls.Add(r, pos.Column, pos.Row);
                    tblParent.SetColumnSpan(r, colSpan);
                }
                else if (ctlParent != null)
                {
                    ctlParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    ctlParent.Controls.Add(r);
                }
            }
            return(r);
        }
Пример #6
0
        protected Label ReplaceWithLable(Control ctl, string value)
        {
            Label r = null;

            if (ctl != null)
            {
                r           = new Label();
                r.Name      = "lbl_" + ctl.Name;
                r.Location  = ctl.Location;
                r.Width     = ctl.Width;
                r.Margin    = ctl.Margin;
                r.Dock      = ctl.Dock;
                r.Anchor    = ctl.Anchor;
                r.Text      = value;
                r.TextAlign = ContentAlignment.MiddleRight;
                r.TabIndex  = ctl.TabIndex;
                r.Tag       = ctl.Tag;
                r.Click    += new EventHandler(this.OnLabelClick);

                Control          ctlParent = ctl.Parent;
                TableLayoutPanel tblParent = ctlParent as TableLayoutPanel;

                if (tblParent != null)
                {
                    TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl);
                    int colSpan = tblParent.GetColumnSpan(ctl);
                    tblParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    tblParent.Controls.Add(r, pos.Column, pos.Row);
                    tblParent.SetColumnSpan(r, colSpan);
                }
                else if (ctlParent != null)
                {
                    ctlParent.Controls.Remove(ctl);
                    ctl.Dispose();
                    ctlParent.Controls.Add(r);
                }
            }
            return(r);
        }
Пример #7
0
        public void TableLayoutPanel_GetColumnSpan_NullControl_ThrowsArgumentNullException()
        {
            var panel = new TableLayoutPanel();

            Assert.Throws <ArgumentNullException>("control", () => panel.GetColumnSpan(null));
        }
Пример #8
0
        /// <summary>
        /// When the DataGridView is visible for the first time a panel is created.
        /// The DataGridView is then removed from the parent control and added as
        /// child to the newly created panel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void changeParent()
        {
            if (!DesignMode && Parent != null)
            {
                summaryControl.InitialHeight = this.refBox.Height;
                summaryControl.Height        = summaryControl.InitialHeight;
                summaryControl.BackColor     = this.RowHeadersDefaultCellStyle.BackColor;
                summaryControl.ForeColor     = Color.Transparent;
                summaryControl.RightToLeft   = this.RightToLeft;
                panel.Bounds    = this.Bounds;
                panel.BackColor = this.BackgroundColor;

                panel.Dock        = this.Dock;
                panel.Anchor      = this.Anchor;
                panel.Padding     = this.Padding;
                panel.Margin      = this.Margin;
                panel.Top         = this.Top;
                panel.Left        = this.Left;
                panel.BorderStyle = this.BorderStyle;

                Margin  = new Padding(0);
                Padding = new Padding(0);
                Top     = 0;
                Left    = 0;

                summaryControl.Dock = DockStyle.Bottom;
                this.Dock           = DockStyle.Fill;

                if (this.Parent is TableLayoutPanel)
                {
                    int rowSpan, colSpan;

                    TableLayoutPanel             tlp     = this.Parent as TableLayoutPanel;
                    TableLayoutPanelCellPosition cellPos = tlp.GetCellPosition(this);

                    rowSpan = tlp.GetRowSpan(this);
                    colSpan = tlp.GetColumnSpan(this);

                    tlp.Controls.Remove(this);
                    tlp.Controls.Add(panel, cellPos.Column, cellPos.Row);
                    tlp.SetRowSpan(panel, rowSpan);
                    tlp.SetColumnSpan(panel, colSpan);
                }
                else
                {
                    Control parent = this.Parent;
                    //remove DataGridView from ParentControls
                    parent.Controls.Remove(this);
                    parent.Controls.Add(panel);
                }

                this.BorderStyle = BorderStyle.None;

                panel.BringToFront();


                hScrollBar.Top   = refBox.Height + 2;
                hScrollBar.Width = this.Width;
                hScrollBar.Left  = this.Left;

                summaryControl.Controls.Add(hScrollBar);
                hScrollBar.BringToFront();
                panel.Controls.Add(this);

                spacePanel           = new Panel();
                spacePanel.BackColor = panel.BackColor;
                spacePanel.Height    = summaryRowSpace;
                spacePanel.Dock      = DockStyle.Bottom;

                panel.Controls.Add(spacePanel);
                panel.Controls.Add(summaryControl);

                resizeHScrollBar();
                adjustSumControlToGrid();
                adjustScrollbarToSummaryControl();

                resizeHScrollBar();
            }
        }
        private AlignUnitsCollection(TableLayoutPanel panel)
        {
            IDictionary <int, int> rowsMapping = this.GetRowsMapping(panel);

            this.unitsCollection = new AlignUnit[rowsMapping.Count, panel.ColumnCount];
            this.RowDeltaValue   = new int[rowsMapping.Count];
            foreach (object obj in panel.Controls)
            {
                Control control = (Control)obj;
                int     row     = panel.GetRow(control);
                int     column  = panel.GetColumn(control);
                if (this.GetControlVisible(control) && row >= 0 && column >= 0)
                {
                    int       num       = rowsMapping[row];
                    int       num2      = column;
                    AlignUnit alignUnit = new AlignUnit(control, panel.GetRowSpan(control), panel.GetColumnSpan(control), num, num2);
                    for (int i = 0; i < alignUnit.ColumnSpan; i++)
                    {
                        this.unitsCollection[num, num2 + i] = alignUnit;
                    }
                    this.unitsList.Add(alignUnit);
                    if (!this.rowUnitsDictionary.ContainsKey(num))
                    {
                        this.rowUnitsDictionary[num] = new List <AlignUnit>();
                    }
                    this.rowUnitsDictionary[num].Add(alignUnit);
                }
            }
            for (int j = 0; j < this.RowCount; j++)
            {
                if (!this.rowUnitsDictionary.ContainsKey(j))
                {
                    this.rowUnitsDictionary[j] = new List <AlignUnit>();
                }
                else
                {
                    this.rowUnitsDictionary[j].Sort();
                }
                this.RowDeltaValue[j] = AlignSettings.DefaultVertical;
            }
            this.UpdateCompareMargin();
        }
Пример #10
0
        private VisualWrapper(Control control)
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            Control          parent      = control.Parent;
            TableLayoutPanel layoutPanel = parent as TableLayoutPanel;

            _control = control;

            this.Size     = control.Size;
            this.Location = control.Location;
            this.Padding  = control.Padding;
            this.Margin   = control.Margin;
            this.Anchor   = control.Anchor;
            this.Dock     = control.Dock;
            this.TabIndex = control.TabIndex;

            int index   = parent.Controls.IndexOf(control);
            int row     = layoutPanel?.GetRow(control) ?? 0;
            int col     = layoutPanel?.GetColumn(control) ?? 0;
            int rowSpan = layoutPanel?.GetRowSpan(control) ?? 0;
            int colSpan = layoutPanel?.GetColumnSpan(control) ?? 0;

            parent.Controls.Remove(control);

            if (layoutPanel != null)
            {
                layoutPanel.Controls.Add(this, col, row);
                layoutPanel.SetRowSpan(this, rowSpan);
                layoutPanel.SetColumnSpan(this, colSpan);
            }
            else
            {
                parent.Controls.Add(this);
                parent.Controls.SetChildIndex(this, index);
            }

            control.Padding      = new Padding();
            control.Margin       = new Padding();
            control.Dock         = DockStyle.None;
            control.Anchor       = AnchorStyles.None;
            control.GotFocus    += ControlFocusChanged;
            control.LostFocus   += ControlFocusChanged;
            control.TextChanged += ControlTextChanged;

            if (control is TextBoxBase)
            {
                this.SetStyle(ControlStyles.Selectable, false);
                ((TextBoxBase)control).BorderStyle = BorderStyle.None;
            }
            else if (control is ComboBox)
            {
                control.Visible = false;

                if (((ComboBox)control).DropDownStyle == ComboBoxStyle.DropDown)
                {
                    _comboTextBox                 = new TextBox();
                    _comboTextBox.Text            = control.Text;
                    _comboTextBox.BorderStyle     = BorderStyle.None;
                    _comboTextBox.KeyDown        += ComboTextBoxKeyDown;
                    _comboTextBox.PreviewKeyDown += ComboTextBoxPreviewKeyDown;
                    _comboTextBox.TextChanged    += ComboTextBoxTextChanged;
                    this.Controls.Add(_comboTextBox);
                    this.SetStyle(ControlStyles.Selectable, false);
                }

                ((ComboBox)control).ItemHeight            = control.Height;
                ((ComboBox)control).SelectedIndexChanged += ComboSelectedIndexChanged;
                ((ComboBox)control).DropDown             += ComboDropDownChanged;
                ((ComboBox)control).DropDownClosed       += ComboDropDownChanged;
            }

            this.Controls.Add(control);
            this.BackColor = control.BackColor;

            OnSizeChanged(new EventArgs());
        }