// This method defines the DragDrop event behavior. 
        protected override void OnDragDrop(DragEventArgs dea)
        {
            base.OnDragDrop(dea);

            // Did a valid move operation occur?
            if (dea.Effect == DragDropEffects.Move)
            {
                // The move operation is valid. Adjust the state
                // of the GridStrip control's TableLayoutPanel,
                // by swapping the positions of the source button
                // and the empty cell button.

                // Get the cell of the control to move.
                TableLayoutPanelCellPosition sourcePos = 
                    tableSettings.GetCellPosition(this.dragButton);

                // Get the cell of the emptyCellButton.
                TableLayoutPanelCellPosition dropPos = 
                    tableSettings.GetCellPosition(this.emptyCellButton);

                // Move the control to the empty cell.
                tableSettings.SetCellPosition(this.dragButton, dropPos);

                // Set the position of the empty cell to 
                // that of the previously occupied cell.
                tableSettings.SetCellPosition(this.emptyCellButton, sourcePos);

                // Reset the drag operation.
                this.dragButton = null;
            }
        }
        public void TableLayoutSettings_SetCellPosition_MultipleTimes_GetReturnsExpected(TableLayoutSettings settings)
        {
            var control = new ScrollableControl();

            settings.SetCellPosition(control, new TableLayoutPanelCellPosition(1, 1));
            Assert.Equal(new TableLayoutPanelCellPosition(1, 1), settings.GetCellPosition(control));

            settings.SetCellPosition(control, new TableLayoutPanelCellPosition(2, 2));
            Assert.Equal(new TableLayoutPanelCellPosition(2, 2), settings.GetCellPosition(control));
        }
        public void TableLayoutSettings_SetCellPosition_ValidControl_GetReturnsExpected(TableLayoutSettings settings, TableLayoutPanelCellPosition value)
        {
            var control = new ScrollableControl();

            settings.SetCellPosition(control, value);
            Assert.Equal(value, settings.GetCellPosition(control));
        }
        public void TableLayoutSettings_GetCellPosition_InvalidControlStub_ReturnsExpected()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            Assert.Equal(new TableLayoutPanelCellPosition(-1, -1), settings.GetCellPosition("control"));
        }
        public void TableLayoutSettings_GetCellPosition_InvalidRow_ThrowsArgumentOutOfRangeException(TableLayoutSettings settings)
        {
            var control = new ScrollableControl();

            settings.SetCellPosition(control, new TableLayoutPanelCellPosition {
                Row = -2
            });
            Assert.Throws <ArgumentOutOfRangeException>("row", () => settings.GetCellPosition(control));
        }
        public void TableLayoutSettings_GetCellPosition_InvalidControl_ThrowsNotSupportedException()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <NotSupportedException>(() => settings.GetCellPosition("control"));
        }
 public void TableLayoutSettings_GetCellPosition_NullControl_ThrowsArgumentNullException(TableLayoutSettings settings)
 {
     Assert.Throws <ArgumentNullException>("control", () => settings.GetCellPosition(null));
 }
        public void TableLayoutSettings_GetCellPosition_NoSuchControl_ReturnsExpected(TableLayoutSettings settings)
        {
            var control = new ScrollableControl();

            Assert.Equal(new TableLayoutPanelCellPosition(-1, -1), settings.GetCellPosition(control));
        }