/*************************************************************
        * Function: chooseBackgroundColorToolStripMenuItem_Click(object sender, EventArgs e)
        * Date Created: March 8, 2017
        * Date Last Modified: March 8, 2017
        * Description: button for change bgcolor
        * Return: void
        *************************************************************/
        private void chooseBackgroundColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int selectedColor = 0;

            List <IUndoRedoCmd> undos = new List <IUndoRedoCmd>();

            ColorDialog colorDialog = new ColorDialog();

            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                selectedColor = colorDialog.Color.ToArgb();

                foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
                {
                    Cell spreadsheetCell = ssheet.GetCell(cell.RowIndex, cell.ColumnIndex);

                    RestoreBGColor tempBGClass = new RestoreBGColor((int)spreadsheetCell.BGColor, spreadsheetCell.Name);

                    undos.Add(tempBGClass);

                    spreadsheetCell.BGColor = (uint)selectedColor;
                }

                multiCmds tempCmd = new multiCmds(undos, "changing cell background color");

                UnRedo.AddUndos(tempCmd);

                refreshUndoRedoButtons();
            }
        }
Esempio n. 2
0
        private void color_changing(object sender, bool custom)
        {
            ColorDialog SelectColor = new ColorDialog();

            if (custom) // user wants to select their own color -> prompts color dialogue
            {
                if (SelectColor.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            else // the user chose one of the pre-selected colors
            {
                if (sender.ToString() == "Reset")
                {
                    SelectColor.Color = System.Drawing.Color.FromArgb(-1);
                }
                if (sender.ToString() == "Green")
                {
                    SelectColor.Color = System.Drawing.Color.FromArgb(192, 255, 192);
                }
                else if (sender.ToString() == "Red")
                {
                    SelectColor.Color = System.Drawing.Color.FromArgb(255, 128, 128);
                }
                else if (sender.ToString() == "Orange")
                {
                    SelectColor.Color = System.Drawing.Color.FromArgb(255, 192, 128);
                }
                else if (sender.ToString() == "Grey")
                {
                    SelectColor.Color = System.Drawing.Color.FromArgb(131, 130, 120);
                }
            }

            DataGridViewSelectedCellCollection CellsChanging = dataGridView1.SelectedCells; // Gets the collection of selected cells
            CmdCollection BGRestore = new CmdCollection();

            if (CellsChanging != null)                           // Ensures that there is at least one selected cell
            {
                foreach (DataGridViewCell cell in CellsChanging) // Foreach cell that has been selected, notify the spreadsheet of that cells property change
                {
                    SpreadsheetCell Changing   = mainSS[cell.RowIndex, cell.ColumnIndex];
                    RestoreBGColor  newRestore = new RestoreBGColor(Changing, Changing.BGColor);

                    Changing.BGColor = SelectColor.Color.ToArgb(); // Converts the chosen color to ARBG integer format
                    BGRestore.Add(newRestore);
                }

                mainSS.PushUndo(BGRestore);                                  // Adds the new restore collection
                undoToolStripMenuItem.Text    = "Undo - " + mainSS.PeekUndo; // Tells the UI which property will be undone
                redoToolStripMenuItem.Enabled = false;
                redoToolStripMenuItem.Text    = "Redo";
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 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);
         }
     }
 }