protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; string[] tableDescription = new string[] { "Table in Auto Size Mode", "Table in Auto Height Mode", "Table in Fit To Shape Mode" }; ENTableBlockResizeMode[] tableBlockResizeMode = new ENTableBlockResizeMode[] { ENTableBlockResizeMode.AutoSize, ENTableBlockResizeMode.AutoHeight, ENTableBlockResizeMode.FitToShape }; double y = 100; for (int i = 0; i < 3; i++) { NShape shape = new NShape(); shape.SetBounds(new NRectangle(100, y, 300, 300)); y += 200; // create table NTableBlock tableBlock = CreateTableBlock(tableDescription[i]); tableBlock.Content.AllowSpacingBetweenCells = false; tableBlock.ResizeMode = tableBlockResizeMode[i]; shape.TextBlock = tableBlock; drawing.ActivePage.Items.AddChild(shape); } }
private NTableBlock CreateTableBlock(string description) { NTableBlock tableBlock = new NTableBlock(4, 3, NBorder.CreateFilledBorder(NColor.Black), new NMargins(1)); NTableBlockContent tableBlockContent = tableBlock.Content; NTableCell tableCell = tableBlock.Content.Rows[0].Cells[0]; tableCell.ColSpan = int.MaxValue; tableCell.Blocks.Clear(); NParagraph par = new NParagraph(description); par.FontStyleBold = true; tableCell.Blocks.Add(par); for (int rowIndex = 1; rowIndex < tableBlockContent.Rows.Count; rowIndex++) { NTableRow row = tableBlockContent.Rows[rowIndex]; for (int colIndex = 0; colIndex < tableBlockContent.Columns.Count; colIndex++) { NTableCell cell = row.Cells[colIndex]; cell.Blocks.Clear(); cell.Blocks.Add(new NParagraph("This is table cell [" + rowIndex.ToString() + ", " + colIndex.ToString() + "]")); } } NTableCellIterator iter = new NTableCellIterator(tableBlockContent); while (iter.MoveNext()) { iter.Current.VerticalAlignment = ENVAlign.Center; iter.Current.HorizontalAlignment = ENAlign.Center; } // make sure all columns are percentage based double percent = 100 / tableBlockContent.Columns.Count; for (int i = 0; i < tableBlockContent.Columns.Count; i++) { tableBlockContent.Columns[i].PreferredWidth = new Nevron.Nov.NMultiLength(Nevron.Nov.ENMultiLengthUnit.Percentage, percent); } return(tableBlock); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; string[] tableDescription = new string[] { "Table With Column Ports", "Table With Row Ports", "Table With Cell Ports", "Table With Grid Ports" }; ENPortsDistributionMode[] tablePortDistributionModes = new ENPortsDistributionMode[] { ENPortsDistributionMode.ColumnsOnly, ENPortsDistributionMode.RowsOnly, ENPortsDistributionMode.CellBased, ENPortsDistributionMode.GridBased }; NTableBlock[] tableBlocks = new NTableBlock[tablePortDistributionModes.Length]; double margin = 40; double tableSize = 200; double gap = (drawing.ActivePage.Width - margin * 2 - tableSize * 2); double yPos = margin; int portDistributionModeIndex = 0; for (int y = 0; y < 2; y++) { double xPos = margin; for (int x = 0; x < 2; x++) { NShape shape = new NShape(); shape.SetBounds(new NRectangle(xPos, yPos, tableSize, tableSize)); xPos += tableSize + gap; // create table NTableBlock tableBlock = CreateTableBlock(tableDescription[portDistributionModeIndex]); // collect the block to connect it to the center shape tableBlocks[portDistributionModeIndex] = tableBlock; tableBlock.Content.AllowSpacingBetweenCells = false; tableBlock.ResizeMode = ENTableBlockResizeMode.FitToShape; tableBlock.PortsDistributionMode = tablePortDistributionModes[portDistributionModeIndex++]; shape.TextBlock = tableBlock; drawing.ActivePage.Items.AddChild(shape); } yPos += tableSize + gap; } NShape centerShape = new NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle); centerShape.Text = "Table Ports allow you to connect tables to other shapes"; centerShape.TextBlock.FontStyleBold = true; ((NTextBlock)centerShape.TextBlock).VerticalAlignment = ENVerticalAlignment.Center; ((NTextBlock)centerShape.TextBlock).HorizontalAlignment = ENAlign.Center; drawing.ActivePage.Items.AddChild(centerShape); double center = drawing.ActivePage.Width / 2.0; double shapeSize = 100; centerShape.SetBounds(new NRectangle(center - shapeSize / 2.0, center - shapeSize / 2.0, shapeSize, shapeSize)); // get the column port for the first column on the bottom side NTableColumnPort columnPort; if (tableBlocks[0].TryGetColumnPort(0, false, out columnPort)) { Connect(columnPort, centerShape.GetPortByName("Left")); } // get the row port for the second row on the left side NTableRowPort rowPort; if (tableBlocks[1].TryGetRowPort(1, true, out rowPort)) { Connect(rowPort, centerShape.GetPortByName("Top")); } // get the cell port of the first cell on the top side NTableCellPort cellPort; if (tableBlocks[2].TryGetCellPort(0, 0, ENTableCellPortDirection.Top, out cellPort)) { Connect(cellPort, centerShape.GetPortByName("Bottom")); } // get the cell port of the first row on the left side NTableRowPort rowPort1; if (tableBlocks[3].TryGetRowPort(0, true, out rowPort1)) { Connect(rowPort1, centerShape.GetPortByName("Right")); } }