Beispiel #1
0
        public static MatrixGrid CreateMatrix(Matrix <T> matrix)
        {
            matrices.Add(matrix);
            var grid = new View.MatrixGrid()
            {
                Parent = panel, Dock = DockStyle.None
            };

            matrix.DisposeEvent += (o, e) => grid.Dispose();
            matrix.SizeChanged  += (o, e) => grid.GridSize = new Size(matrix.columnsCount, matrix.rowsCount);
            grid.GridSize        = new Size(matrix.columnsCount, matrix.rowsCount);
            matrix.Changed      += (o, e) => grid.Invalidate();
            grid.lines           = matrix.lines;
            grid.CellNeeded     += (o, e) =>
            {
                try
                {
                    e.Value = matrix[e.Cell.Y, e.Cell.X].ToString();
                }
                catch
                {
                    e.Value = "err";
                }
            };

            matricesView.Add(new KeyValuePair <Matrix <T>, MatrixGrid>(matrix, grid));
            return(grid);
        }
Beispiel #2
0
        public static MatrixGrid CreateMatrix(T[,] data)
        {
            Matrix <T> matrix = new Matrix <T>(data.GetLength(0), data.GetLength(1));

            matrices.Add(matrix);
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    matrix[i, j] = data[i, j];
                }
            }
            var grid = new View.MatrixGrid()
            {
                Parent = panel, Dock = DockStyle.None
            };

            matrix.DisposeEvent += (o, e) => grid.Dispose();

            matrix.SizeChanged += (o, e) => grid.GridSize = new Size(matrix.columnsCount, matrix.rowsCount);
            matrix.Changed     += (o, e) => grid.Invalidate();
            grid.GridSize       = new Size(data.GetLength(1), data.GetLength(0));
            grid.lines          = matrix.lines;
            grid.CellNeeded    += (o, e) =>
            {
                try
                {
                    e.Value = matrix[e.Cell.Y, e.Cell.X].ToString();
                }
                catch
                {
                    e.Value = "err";
                }
            };


            matricesView.Add(new KeyValuePair <Matrix <T>, MatrixGrid>(matrix, grid));
            return(grid);
        }