/// <summary> /// Show matrix in window /// </summary> /// <param name="mat">MatrixMB</param> /// <param name="title">String - window title - optional</param> /// <returns>System.Windows.Forms.Form</returns> public static Form ToWindow(this LearnByErrorLibrary.MatrixMB mat, String title = "") { Form f = new Form(); //f.Icon = Properties.Resources.logo; f.Text = title == "" ? mat.Name : title; f.Width = 500; f.Height = 400; f.StartPosition = FormStartPosition.CenterScreen; DataGridView grid = new DataGridView(); grid.Dock = DockStyle.Fill; grid.ColumnHeadersVisible = false; grid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; grid.AutoSize = true; grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; grid.EditMode = DataGridViewEditMode.EditProgrammatically; grid.ReadOnly = true; grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; f.Controls.Add(grid); var rowCount = mat.Rows; var rowLength = mat.Cols; for (int i = 0; i < rowLength; i++) { grid.Columns.Add("data" + (i + 1).ToString(), ""); } for (int rowIndex = 0; rowIndex < rowCount; ++rowIndex) { var row = new DataGridViewRow(); for (int columnIndex = 0; columnIndex < rowLength; ++columnIndex) { row.Cells.Add(new DataGridViewTextBoxCell() { Value = mat.Data[rowIndex][columnIndex] }); } grid.Rows.Add(row); } return(f); }
/// <summary> /// Adds learning data /// </summary> /// <param name="document">Document - pdf document</param> /// <param name="mat">MatrixMB - matrix object</param> private static void AddMatrixTable(Document document, LearnByErrorLibrary.MatrixMB mat) { try { var name = "Dane wejściowe" + " " + (mat.Name != "" ? " - " + mat.Name : ""); Paragraph paragraph = document.LastSection.AddParagraph(name, "Heading2"); paragraph.AddBookmark("Dane wejściowe"); Table table = new Table(); table.Borders.Width = 0.75; for (int col = 0; col < mat.Cols; col++) { Column column = table.AddColumn(Unit.FromCentimeter(1.5)); column.Format.Alignment = ParagraphAlignment.Center; } for (int r = 0; r < mat.Rows; r++) { Row row = table.AddRow(); row.Shading.Color = r % 2 == 0 ? Colors.LightGray : Colors.LightBlue; for (int c = 0; c < mat.Cols; c++) { Cell cell = row.Cells[c]; cell.AddParagraph(mat.Data[r][c].ToString()); } } table.SetEdge(0, 0, mat.Cols, mat.Rows, Edge.Box, BorderStyle.Single, 0.5, Colors.Black); document.LastSection.Add(table); } catch (Exception ex) { ex.ToLog(); } }