// 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_SetCellPosition_InvalidControlStub_GetReturnsExpected()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            settings.SetCellPosition("control", new TableLayoutPanelCellPosition());
            Assert.Equal(new TableLayoutPanelCellPosition(), settings.GetCellPosition("control"));
        }
        public void TableLayoutSettings_SetCellPosition_InvalidControl_ThrowsNotSupportedException()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <NotSupportedException>(() => settings.SetCellPosition("control", new TableLayoutPanelCellPosition()));
        }
        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_SetCellPosition_NullControl_ThrowsArgumentNullException(TableLayoutSettings settings)
 {
     Assert.Throws <ArgumentNullException>("control", () => settings.SetCellPosition(null, new TableLayoutPanelCellPosition()));
 }
Пример #8
0
 public ColorTable()
 {
     this.SuspendLayout();
     // Set yellow as default highlight color.
     selectedColor = Color.Yellow;
     this.LayoutStyle = ToolStripLayoutStyle.Table;
     TableLayoutSettings layout = (TableLayoutSettings)this.LayoutSettings;
     layout.ColumnCount = 5;
     layout.RowCount = 3;
     // Highlight color values used here have been shamelessly
     // copied from microsoft word's Highlight color values.
     Color[] colors = new Color[] { Color.FromArgb(255, 255, 0), Color.FromArgb(0, 255, 0),
     Color.FromArgb(0, 255, 255), Color.FromArgb(255, 0, 255), Color.FromArgb(0, 0, 255), Color.FromArgb(255, 0, 0),
     Color.FromArgb(0, 0, 128), Color.FromArgb(0, 128, 128), Color.FromArgb(0, 128, 0), Color.FromArgb(128, 0, 128),
     Color.FromArgb(128, 0, 0), Color.FromArgb(128, 128, 0), Color.FromArgb(128, 128, 128), Color.FromArgb(192, 192, 192),
     Color.FromArgb(0, 0, 0) };
     // ToolTipText used. Same text as MS Word, what a coincidence!
     string[] colorNames = new string[] { "Yellow", "Bright Green", "Turquoise", "Pink", "Blue", "Red", "Dark Blue",
         "Teal", "Green", "Violet", "Dark Red", "Dark Yellow", "Gray-50%", "Gray-25%", "Black" };
     // Set rectangle and padding values so that
     // when an item is selected the selection
     // frame highlights the color "square" with
     // even spacing around it.          
     Rectangle rc = new Rectangle(1, 1, 11, 11);
     Padding itemPadding = new Padding(2, 1, 2, 1);
     // To get selection frame perfectly centered
     // The size of the bitmap image to draw on is
     // 13 pixels wide and 12 pixels high.
      int bmWidth = 13;
     int bmHeight = 12;
     // Add the Fourteen colors to the dropdown.
     for (int i = 0; i < 15; i++)
     {
         Bitmap bm = new Bitmap(bmWidth, bmHeight);
         using (Graphics g = Graphics.FromImage(bm))
         {
             // g.Clear(colors[i]);
             g.FillRectangle(new SolidBrush(colors[i]), rc);
             g.DrawRectangle(Pens.Gray, 1, 0, 11, 11);
         }
         ToolStripMenuItem item = (new ToolStripMenuItem(bm));
         this.Items.Add(item);
         item.Padding = itemPadding;
         item.ImageScaling = ToolStripItemImageScaling.None;
         item.ImageAlign = ContentAlignment.MiddleCenter;
         item.DisplayStyle = ToolStripItemDisplayStyle.Image;
         item.ToolTipText = colorNames[i];
         item.MouseDown += color_MouseDown;
         item.Tag = colors[i];
         this.Opening += ColorTable_Opening;
     }
     // Select yellow item as default selected color.
     this.Items[0].Select();
     // Also add an option to clear existing highlighting
     // back to default/no highlighting.
     ToolStripMenuItem noColor = new ToolStripMenuItem("None");
     this.Items.Add(noColor);
     layout.SetCellPosition(noColor, new TableLayoutPanelCellPosition(0, 0));
     layout.SetColumnSpan(noColor, 5);
     // The color white is used to indicate "No Highlight".
     Bitmap bmp = new Bitmap(1, 1);
     using (Graphics g = Graphics.FromImage(bmp))
     {
         g.Clear(Color.White);
     }
     noColor.Image = bmp;
     noColor.Tag = Color.White;
     noColor.DisplayStyle = ToolStripItemDisplayStyle.Text;
     noColor.Dock = DockStyle.Fill;
     noColor.ToolTipText = "No Highlight";
     noColor.MouseDown += color_MouseDown;
     this.ResumeLayout();
 }
Пример #9
0
        public ColorTable()
        {
            this.SuspendLayout();
            // Set yellow as default highlight color.
            selectedColor    = Color.Yellow;
            this.LayoutStyle = ToolStripLayoutStyle.Table;
            TableLayoutSettings layout = (TableLayoutSettings)this.LayoutSettings;

            layout.ColumnCount = 8;
            layout.RowCount    = 5;

            //


            // Highlight color values used here have been shamelessly
            // copied from microsoft word's Highlight color values.
            Color[] colors = new Color[] { Black, Brown, OliveGreen, DarkGreen, DarkTeal, DarkBlue, Indigo, Gray80,
                                           DarkRed, Orange, DarkYellow, Green, Teal, Blue, BlueGray, Gray50,
                                           Red, LightOrange, Lime, SeaGreen, Aqua, LightBlue, Violet, Gray40,
                                           Pink, Gold, Yellow, BrightGreen, Turquoise, SkyBlue, Plum, Gray25,
                                           Rose, Tan, LightYellow, LightGreen, LightTurquoise, PaleBlue, Lavender, White };
            // ToolTipText used. Same text as MS Word, what a coincidence!
            string[] colorNames = new string[] {
                "Black", "Brown", "OliveGreen", "DarkGreen", "DarkTeal", "DarkBlue", "Indigo", "Gray80",
                "DarkRed", "Orange", "DarkYellow", "Green", "Teal", "Blue", "BlueGray", "Gray50",
                "Red", "LightOrange", "Lime", "SeaGreen", "Aqua", "LightBlue", "Violet", "Gray40",
                "Pink", "Gold", "Yellow", "BrightGreen", "Turquoise", "SkyBlue", "Plum", "Gray25",
                "Rose", "Tan", "LightYellow", "LightGreen", "LightTurquoise", "PaleBlue", "Lavender", "White"
            };
            // Set rectangle and padding values so that
            // when an item is selected the selection
            // frame highlights the color "square" with
            // even spacing around it.
            Rectangle rc          = new Rectangle(1, 1, 11, 11);
            Padding   itemPadding = new Padding(2, 1, 2, 1);
            // To get selection frame perfectly centered
            // The size of the bitmap image to draw on is
            // 13 pixels wide and 12 pixels high.
            int bmWidth  = 13;
            int bmHeight = 12;

            // Add the Fourteen colors to the dropdown.
            for (int i = 0; i < colors.Length; i++)
            {
                Bitmap bm = new Bitmap(bmWidth, bmHeight);
                using (Graphics g = Graphics.FromImage(bm))
                {
                    // g.Clear(colors[i]);
                    g.FillRectangle(new SolidBrush(colors[i]), rc);
                    g.DrawRectangle(Pens.Gray, 1, 0, 11, 11);
                }
                ToolStripMenuItem item = (new ToolStripMenuItem(bm));
                this.Items.Add(item);
                item.Padding      = itemPadding;
                item.ImageScaling = ToolStripItemImageScaling.None;
                item.ImageAlign   = ContentAlignment.MiddleCenter;
                item.DisplayStyle = ToolStripItemDisplayStyle.Image;
                item.ToolTipText  = colorNames[i];
                item.MouseDown   += color_MouseDown;
                item.Tag          = colors[i];
                this.Opening     += ColorTable_Opening;
            }
            // Select yellow item as default selected color.
            this.Items[0].Select();
            // Also add an option to clear existing highlighting
            // back to default/no highlighting.
            ToolStripMenuItem noColor = new ToolStripMenuItem("None");

            this.Items.Add(noColor);
            layout.SetCellPosition(noColor, new TableLayoutPanelCellPosition(0, 0));
            layout.SetColumnSpan(noColor, layout.ColumnCount);
            // The color white is used to indicate "No Highlight".
            Bitmap bmp = new Bitmap(1, 1);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.Clear(Color.White);
            }
            noColor.Image        = bmp;
            noColor.Tag          = Color.White;
            noColor.DisplayStyle = ToolStripItemDisplayStyle.Text;
            noColor.Dock         = DockStyle.Fill;
            noColor.ToolTipText  = "No Highlight";
            noColor.MouseDown   += color_MouseDown;
            this.ResumeLayout();
        }