private void dataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { Cell currentCell = this.test.GetCell(e.RowIndex, e.ColumnIndex); dataGridView[e.ColumnIndex, e.RowIndex].Value = currentCell.Text; Color newColor = Color.FromArgb((int)currentCell.BGColor); dataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = newColor; ICmd text = new RestoreText(currentCell, currentCell.Text); ICmd bgcolor = new RestoreBGColor(currentCell, currentCell.BGColor); ICmd multi = new MultiCmd(); MultiCmd temp = multi as MultiCmd; temp.Add(text); temp.Add(bgcolor); test.AddUndo(multi); }
private void changeCellBackgroundColorToolStripMenuItem_Click(object sender, EventArgs e) { ColorDialog myDialog = new ColorDialog(); MultiCmd allCommands = new MultiCmd(); if (myDialog.ShowDialog() == DialogResult.OK) { foreach (DataGridViewCell c in dataGridView1.SelectedCells) { uint argb = ColorToUInt(myDialog.Color); Cell tempCell = mySpreadsheet.getCell(c.RowIndex, c.ColumnIndex); ICmd temp = new RestoreBG(tempCell, tempCell.BGColor); allCommands.addCommands(temp); mySpreadsheet.getCell(c.RowIndex, c.ColumnIndex).BGColor = argb; } mySpreadsheet.AddUndo(allCommands); } }
private void changeColorToolStripMenuItem_Click(object sender, EventArgs e) { if (colorDialog.ShowDialog() == DialogResult.OK) { Color newColor = colorDialog.Color; //Save the user selected color dataGridView.BackgroundColor = newColor; //Save the new color in dataGridView.BackgroundColor var currentCells = dataGridView.SelectedCells; //Get the highlighted cells for (int i = 0; i < currentCells.Count; i++) { Cell currentCell = test.GetCell(currentCells[i].RowIndex, currentCells[i].ColumnIndex); currentCell.BGColor = (uint)newColor.ToArgb(); //Update the background color of each selected cell to the saved color the user selected ICmd text = new RestoreText(currentCell, currentCell.Text); ICmd bgcolor = new RestoreBGColor(currentCell, currentCell.BGColor); ICmd multi = new MultiCmd(); MultiCmd temp = multi as MultiCmd; temp.Add(text); temp.Add(bgcolor); test.AddUndo(multi); } } }