public void TableLayoutSettings_SetRow_MultipleTimes_GetReturnsExpected(TableLayoutSettings settings) { var control = new ScrollableControl(); settings.SetRow(control, 1); Assert.Equal(1, settings.GetRow(control)); settings.SetRow(control, 2); Assert.Equal(2, settings.GetRow(control)); }
public void TableLayoutSettings_SetRow_ValidControl_GetReturnsExpected(TableLayoutSettings settings, int value) { var control = new ScrollableControl(); settings.SetRow(control, value); Assert.Equal(value, settings.GetRow(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); }
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_SetRow_InvalidControlStub_GetReturnsExpected() { var converter = new TableLayoutSettingsTypeConverter(); TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(converter.ConvertFrom(@"<?xml version=""1.0"" encoding=""utf-16""?><Root />")); settings.SetRow("control", 1); Assert.Equal(1, settings.GetRow("control")); }
public void TableLayoutSettings_SetRow_InvalidControl_ThrowsNotSupportedException() { var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table }; TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings); Assert.Throws <NotSupportedException>(() => settings.SetRow("control", 1)); }
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)); } }
public SearchTextBoxStrip() { _textBox = new SearchTextBoxTextBox(); _textBoxHost = new ToolStripControlHost(_textBox) { Dock = DockStyle.Fill, }; _searchButton = new ToolStripSplitButton(Resources.Images.SearchStart) { Dock = DockStyle.Fill, }; SuspendLayout(); Dock = DockStyle.Fill; GripStyle = ToolStripGripStyle.Hidden; LayoutStyle = ToolStripLayoutStyle.Table; Renderer = new SearchTextBoxRenderer(); Items.Add(_textBoxHost); Items.Add(_searchButton); TableLayoutSettings.RowCount = 1; TableLayoutSettings.ColumnCount = 2; TableLayoutSettings.ColumnStyles.Clear(); TableLayoutSettings.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f)); TableLayoutSettings.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); TableLayoutSettings.SetRow(_textBoxHost, 0); TableLayoutSettings.SetRow(_searchButton, 0); TableLayoutSettings.SetColumn(_textBoxHost, 0); TableLayoutSettings.SetColumn(_searchButton, 1); ResumeLayout(true); }
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_SetRow_InvalidRow_ThrowsArgumentOutOfRangeException(TableLayoutSettings settings) { Assert.Throws <ArgumentOutOfRangeException>("row", () => settings.SetRow("control", -2)); }
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_SetRow_NullControl_ThrowsArgumentNullException(TableLayoutSettings settings) { Assert.Throws <ArgumentNullException>("control", () => settings.SetRow(null, 1)); }