public void TableLayoutSettings_SetColumnSpan_MultipleTimes_GetReturnsExpected(TableLayoutSettings settings)
        {
            var control = new ScrollableControl();

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

            settings.SetColumnSpan(control, 2);
            Assert.Equal(2, settings.GetColumnSpan(control));
        }
        public void TableLayoutSettingsTypeConverter_ConvertTo_HasStylesAndControls_ReturnsExpected()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };

            toolStrip.Items.Add(new ToolStripLabel("text"));

            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            settings.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize, 1));
            settings.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 2));
            settings.RowStyles.Add(new RowStyle(SizeType.AutoSize, 1));
            settings.RowStyles.Add(new RowStyle(SizeType.Absolute, 2));

            var control = new ScrollableControl();

            settings.SetColumnSpan(control, 1);
            settings.SetRowSpan(control, 2);
            settings.SetColumn(control, 3);
            settings.SetRow(control, 4);

            var    converter = new TableLayoutSettingsTypeConverter();
            string result    = Assert.IsType <string>(converter.ConvertTo(settings, typeof(string)));

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings><Controls /><Columns Styles=""AutoSize,1,Absolute,2"" /><Rows Styles=""AutoSize,1,Absolute,2"" /></TableLayoutSettings>", result);
        }
        public void TableLayoutSettings_SetColumnSpan_ValidControl_GetReturnsExpected(TableLayoutSettings settings, int value)
        {
            var control = new ScrollableControl();

            settings.SetColumnSpan(control, value);
            Assert.Equal(value, settings.GetColumnSpan(control));
        }
Пример #4
0
        private int ParseControl(XmlDocument xmldoc, TableLayoutSettings settings)
        {
            int count = 0;

            foreach (XmlNode node in xmldoc.GetElementsByTagName("Control"))
            {
                if (node.Attributes["Name"] == null || string.IsNullOrEmpty(node.Attributes["Name"].Value))
                {
                    continue;
                }
                if (node.Attributes["Row"] != null)
                {
                    settings.SetRow(node.Attributes["Name"].Value, GetValue(node.Attributes["Row"].Value));
                    count++;
                }
                if (node.Attributes["RowSpan"] != null)
                {
                    settings.SetRowSpan(node.Attributes["Name"].Value, GetValue(node.Attributes["RowSpan"].Value));
                }
                if (node.Attributes["Column"] != null)
                {
                    settings.SetColumn(node.Attributes["Name"].Value, GetValue(node.Attributes["Column"].Value));
                }
                if (node.Attributes["ColumnSpan"] != null)
                {
                    settings.SetColumnSpan(node.Attributes["Name"].Value, GetValue(node.Attributes["ColumnSpan"].Value));
                }
            }
            return(count);
        }
        public void TableLayoutSettings_SetColumnSpan_NullControlStub_ThrowsArgumentNullException()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            Assert.Throws <ArgumentNullException>("control", () => settings.SetColumnSpan(null, 1));
            Assert.Throws <ArgumentNullException>("control", () => settings.GetColumnSpan(null));
        }
        public void TableLayoutSettings_SetColumnSpan_InvalidControlStub_GetReturnsExpected()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            settings.SetColumnSpan("control", 1);
            Assert.Equal(1, settings.GetColumnSpan("control"));
        }
Пример #7
0
        public void TableLayoutSettings_SetColumnSpan_NullControl_ThrowsNullReferenceException()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <NullReferenceException>(() => settings.SetColumnSpan(null, 1));
        }
        public void TableLayoutSettings_SetColumnSpan_NullControl_ThrowsArgumentNullException(int value)
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <ArgumentNullException>("control", () => settings.SetColumnSpan(null, value));
        }
        public void TableLayoutSettings_SetColumnSpan_InvalidValue_ThrowsArgumentOutOfRangeException(int value)
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <ArgumentOutOfRangeException>("value", () => settings.SetColumnSpan("control", value));
        }
        public void TableLayoutSettings_SetColumnSpan_InvalidControl_ThrowsNotSupportedException()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <NotSupportedException>(() => settings.SetColumnSpan("control", 1));
        }
        public void TableLayoutSettingsTypeConverter_ConvertTo_HasControlChildWithoutNameStub_ReturnsExpected()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            Assert.Throws <ArgumentNullException>("control", () => settings.SetColumnSpan(null, 1));
            string result = Assert.IsType <string>(converter.ConvertTo(settings, typeof(string)));

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings><Controls /><Columns Styles="""" /><Rows Styles="""" /></TableLayoutSettings>", result);
        }
Пример #12
0
 // Add an item to the downdrop that takes up the given number of columns.
 void AddItem(ToolStripItem item, int columns, bool updateInfoOnMouseEnter)
 {
     if (updateInfoOnMouseEnter)
     {
         item.MouseEnter += UpdateInfoLabel;
     }
     dropdown.Items.Add(item);
     if (columns > 1)
     {
         tableLayoutSettings.SetColumnSpan(item, columns);
     }
 }
Пример #13
0
        public void TableLayoutPanel_LayoutSettings_SetStubWithControls_Success()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            var panel     = new TableLayoutPanel();

            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));
            var columnStyle = new ColumnStyle(SizeType.Percent, 1);
            var rowStyle    = new RowStyle(SizeType.Percent, 1);

            settings.SetColumnSpan("name", 1);
            settings.SetRowSpan("name", 2);
            settings.SetColumn("name", 3);
            settings.SetRow("name", 4);
            settings.SetColumnSpan("noSuchName", 5);
            settings.SetRowSpan("noSuchName", 6);
            settings.SetColumn("noSuchName", 7);
            settings.SetRow("noSuchName", 8);
            settings.ColumnStyles.Add(columnStyle);
            settings.RowStyles.Add(rowStyle);

            var controlWithName = new ScrollableControl {
                Name = "name"
            };
            var controlWithDefaultName = new ScrollableControl();
            var controlWithoutName     = new ControlWithoutName();

            panel.Controls.Add(controlWithName);
            panel.Controls.Add(controlWithDefaultName);
            panel.Controls.Add(controlWithoutName);

            panel.LayoutSettings = settings;
            Assert.Equal(columnStyle, Assert.Single(panel.LayoutSettings.ColumnStyles));
            Assert.Equal(rowStyle, Assert.Single(panel.LayoutSettings.RowStyles));

            Assert.Equal(1, panel.LayoutSettings.GetColumnSpan(controlWithName));
            Assert.Equal(2, panel.LayoutSettings.GetRowSpan(controlWithName));
            Assert.Equal(3, panel.LayoutSettings.GetColumn(controlWithName));
            Assert.Equal(4, panel.LayoutSettings.GetRow(controlWithName));
        }
        public void TableLayoutSettingsTypeConverter_ConvertTo_StubWithChildren_ReturnsExpected()
        {
            var converter = new TableLayoutSettingsTypeConverter();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />"));

            settings.SetColumnSpan("name", 1);
            settings.SetRowSpan("name", 2);
            settings.SetColumn("name", 3);
            settings.SetRow("name", 4);

            string result = Assert.IsType <string>(converter.ConvertTo(settings, typeof(string)));

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings><Controls><Control Name=""name"" Row=""4"" RowSpan=""2"" Column=""3"" ColumnSpan=""1"" /></Controls><Columns Styles="""" /><Rows Styles="""" /></TableLayoutSettings>", result);
        }
        public void TableLayoutSettingsTypeConverter_ConvertTo_HasControlChildren_ReturnsExpected()
        {
            var panel   = new TableLayoutPanel();
            var control = new ScrollableControl();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(panel.LayoutSettings);

            panel.Controls.Add(control);
            settings.SetColumnSpan(control, 1);
            settings.SetRowSpan(control, 2);
            settings.SetColumn(control, 3);
            settings.SetRow(control, 4);

            var    converter = new TableLayoutSettingsTypeConverter();
            string result    = Assert.IsType <string>(converter.ConvertTo(settings, typeof(string)));

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings><Controls><Control Name="""" Row=""4"" RowSpan=""2"" Column=""3"" ColumnSpan=""1"" /></Controls><Columns Styles="""" /><Rows Styles="""" /></TableLayoutSettings>", result);
        }
 private void ParseControls(TableLayoutSettings settings, XmlNodeList controlXmlFragments)
 {
     foreach (XmlNode node in controlXmlFragments)
     {
         string attributeValue = this.GetAttributeValue(node, "Name");
         if (!string.IsNullOrEmpty(attributeValue))
         {
             int row    = this.GetAttributeValue(node, "Row", -1);
             int num2   = this.GetAttributeValue(node, "RowSpan", 1);
             int column = this.GetAttributeValue(node, "Column", -1);
             int num4   = this.GetAttributeValue(node, "ColumnSpan", 1);
             settings.SetRow(attributeValue, row);
             settings.SetColumn(attributeValue, column);
             settings.SetRowSpan(attributeValue, num2);
             settings.SetColumnSpan(attributeValue, num4);
         }
     }
 }
        private void ParseControls(TableLayoutSettings settings, XmlNodeList controlXmlFragments)
        {
            foreach (XmlNode controlXmlNode in controlXmlFragments)
            {
                string name = GetAttributeValue(controlXmlNode, "Name");

                if (!string.IsNullOrEmpty(name))
                {
                    int row        = GetAttributeValue(controlXmlNode, "Row", /*default*/ -1);
                    int rowSpan    = GetAttributeValue(controlXmlNode, "RowSpan", /*default*/ 1);
                    int column     = GetAttributeValue(controlXmlNode, "Column", /*default*/ -1);
                    int columnSpan = GetAttributeValue(controlXmlNode, "ColumnSpan", /*default*/ 1);

                    settings.SetRow(name, row);
                    settings.SetColumn(name, column);
                    settings.SetRowSpan(name, rowSpan);
                    settings.SetColumnSpan(name, columnSpan);
                }
            }
        }
        public void TableLayoutSettings_Serialize_Deserialize_Success()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            var columnStyle = new ColumnStyle(SizeType.Percent, 1);
            var rowStyle    = new RowStyle(SizeType.Percent, 1);

            var controlWithName = new ScrollableControl {
                Name = "name"
            };

            settings.SetColumnSpan(controlWithName, 1);
            settings.SetRowSpan(controlWithName, 2);
            settings.SetColumn(controlWithName, 3);
            settings.SetRow(controlWithName, 4);
            settings.ColumnStyles.Add(columnStyle);
            settings.RowStyles.Add(rowStyle);

            using (var stream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, settings);
                stream.Seek(0, SeekOrigin.Begin);

                TableLayoutSettings result = Assert.IsType <TableLayoutSettings>(formatter.Deserialize(stream));
                Assert.Equal(columnStyle.SizeType, ((ColumnStyle)Assert.Single(result.ColumnStyles)).SizeType);
                Assert.Equal(columnStyle.Width, ((ColumnStyle)Assert.Single(result.ColumnStyles)).Width);
                Assert.Equal(rowStyle.SizeType, ((RowStyle)Assert.Single(result.RowStyles)).SizeType);
                Assert.Equal(rowStyle.Height, ((RowStyle)Assert.Single(result.RowStyles)).Height);

                Assert.Equal(1, result.GetColumnSpan(controlWithName));
                Assert.Equal(1, result.GetRowSpan(controlWithName));
                Assert.Equal(-1, result.GetColumn(controlWithName));
                Assert.Equal(-1, result.GetRow(controlWithName));
            }
        }
Пример #19
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();
        }
Пример #20
0
 public void SetColumnSpan(object target, int value)
 {
     TableLayoutSettings.SetColumnSpan(target, value);
 }
       private void ParseControls(TableLayoutSettings settings, XmlNodeList controlXmlFragments) {
           foreach (XmlNode controlXmlNode in controlXmlFragments) {
               string name     = GetAttributeValue(controlXmlNode, "Name");

               if (!string.IsNullOrEmpty(name)) {
                   int row        = GetAttributeValue(controlXmlNode, "Row",       /*default*/-1);
                   int rowSpan    = GetAttributeValue(controlXmlNode, "RowSpan",   /*default*/1);
                   int column     = GetAttributeValue(controlXmlNode, "Column",    /*default*/-1);
                   int columnSpan = GetAttributeValue(controlXmlNode, "ColumnSpan",/*default*/1);
       
                   settings.SetRow(name, row);
                   settings.SetColumn(name, column);
                   settings.SetRowSpan(name, rowSpan);
                   settings.SetColumnSpan(name, columnSpan);
               }
               
           }
       
       
       }
Пример #22
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();
 }
		private int ParseControl (XmlDocument xmldoc, TableLayoutSettings settings)
		{
			int count = 0;
			foreach (XmlNode node in xmldoc.GetElementsByTagName ("Control")) {
				if (node.Attributes["Name"] == null || string.IsNullOrEmpty(node.Attributes["Name"].Value))
					continue;
				if (node.Attributes["Row"] != null) {
					settings.SetRow (node.Attributes["Name"].Value, GetValue (node.Attributes["Row"].Value));
					count++;
				}
				if (node.Attributes["RowSpan"] != null) {
					settings.SetRowSpan (node.Attributes["Name"].Value, GetValue (node.Attributes["RowSpan"].Value));
				}
				if (node.Attributes["Column"] != null)
					settings.SetColumn (node.Attributes["Name"].Value, GetValue (node.Attributes["Column"].Value));
				if (node.Attributes["ColumnSpan"] != null)
					settings.SetColumnSpan (node.Attributes["Name"].Value, GetValue (node.Attributes["ColumnSpan"].Value));
			}
			return count;
		}