예제 #1
0
        //When user clicks on the text box, update the selected cell. Might be redundant.
        private void textBoxFocusGot(object sender, EventArgs e)
        {
            TextBox active = (TextBox)sender;

            Int32 selectedCellCount =
                dataGridView1.GetCellCount(DataGridViewElementStates.Selected);

            if (selectedCellCount == 1 && dataGridView1.CurrentCell.Value != null)
            {
                selectedCell = Sheet.GetCell(dataGridView1.SelectedCells[0].RowIndex, dataGridView1.SelectedCells[0].ColumnIndex);
            }
        }
예제 #2
0
        public Form1()
        {
            //setting datagrid properties

            InitializeComponent();
            dataGridView1.ColumnCount = 26;
            dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;

            dataGridView1.RowCount = 50;
            dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;

            // default header style for now

            //generate column names
            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                dataGridView1.Columns[i].Name = Convert.ToChar(65 + i).ToString();
            }

            //generate row headers
            for (int i = 1; i <= dataGridView1.RowCount; i++)
            {
                dataGridView1.Rows[i - 1].HeaderCell.Value = (i).ToString();
            }

            Sheet = new CptS321.Spreadsheet(dataGridView1.RowCount, dataGridView1.ColumnCount);

            //if CellPropertyChanged event is fired, UpdateCell is called
            //"Subscribing" to this Spreadsheet's CellPropertyChanged event
            Sheet.CellPropertyChanged += UpdateCell;
            textBox1.LostFocus        += textBoxFocusLost;
            textBox1.GotFocus         += textBoxFocusGot;
            selectedCell = Sheet.GetCell(0, 0);
        }
예제 #3
0
        public void TestSpreadsheet()
        {
            // Test that the Bounds of the Spreadsheet are within the Requirements
            CptS321.Spreadsheet spreadsheet = new CptS321.Spreadsheet(10, 10);
            Assert.That(spreadsheet.RowCount >= 1 && spreadsheet.RowCount <= 100);
            Assert.That(spreadsheet.ColumnCount >= 1 && spreadsheet.ColumnCount <= 100);

            // Test that trying to access a cell outside the array throws an error
            Assert.Throws <IndexOutOfRangeException>(() => spreadsheet.GetCell(10, 11));
        }
예제 #4
0
        /// <summary>
        /// Fires when Background Color Clicked
        /// </summary>
        /// <param name="sender">UI Color Menu</param>
        /// <param name="e">Event arguments</param>
        private void BackgroundColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Open Color Dialog box for user to select a new color
            ColorDialog colorDialog = new ColorDialog();

            // Store a list of commands for undo / redo
            List <SpreadsheetEngine.ICommand> restoreBGColorCommands = new List <SpreadsheetEngine.ICommand>();

            // When the user selects a new color
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                // Iterate through each of the selected cells
                foreach (DataGridViewCell cell in dataGridView.SelectedCells)
                {
                    // Covert to spreadsheetCell location
                    CptS321.SpreadsheetCell spreadsheetCell = spreadsheet.GetCell((uint)cell.RowIndex, (uint)cell.ColumnIndex);
                    uint oldColor = spreadsheetCell.BGColor;
                    uint newColor = (uint)colorDialog.Color.ToArgb();
                    spreadsheetCell.BGColor = newColor;

                    // Create the undo command
                    SpreadsheetEngine.RestoreBGColorCommand restoreColor = new SpreadsheetEngine.RestoreBGColorCommand(spreadsheetCell, oldColor, newColor);
                    restoreBGColorCommands.Add(restoreColor);
                }

                // Add command list to the stack
                spreadsheet.AddUndo(restoreBGColorCommands);
                this.undoToolStripMenuItem.Enabled = true;

                // Check redo stack, clear if not already empty
                if (!this.spreadsheet.RedoStackIsEmpty())
                {
                    this.spreadsheet.ClearRedoStack();
                }
            }

            // Update button labels and enabled state
            UpdateToolStripMenu();
        }