// advanced form. Auto generate doesn't change when I fix the name.... private void button1_Click(object sender, EventArgs e) { int rate; string mode; bool setAll = false; if (seqDataGridView.SelectedCells.Count == 1) { DataGridViewCustomCell customCell = (DataGridViewCustomCell)seqDataGridView.SelectedCells[0]; rate = customCell.rate; mode = customCell.mode; setAll = customCell.RowIndex == 3 ? true : false; } else if (seqDataGridView.SelectedCells.Count > 1) { DataGridViewCustomCell customCell = (DataGridViewCustomCell)seqDataGridView.SelectedCells[seqDataGridView.SelectedCells.Count - 1]; rate = customCell.rate; mode = customCell.mode; } else { return; //exit if nothing is selected } var popup = new AdvancedSettingsForm(rate, mode); popup.ShowDialog(); if (popup.DialogResult == DialogResult.OK && seqDataGridView.SelectedCells.Count > 0) { CellModeEvaluation evaluation = new CellModeEvaluation(); for (int i = 0; i < seqDataGridView.SelectedCells.Count; i++) { DataGridViewCustomCell cell = (DataGridViewCustomCell)seqDataGridView.SelectedCells[i]; cell.rate = popup.rate; cell.mode = popup.mode; if (cell.RowIndex == 3) { evaluation.colorTouchedRows.Add(cell.ColumnIndex); } else { evaluation.normalTouchedRows.Add(cell.ColumnIndex); } } evaluation.colorTouchedRows = evaluation.colorTouchedRows.Distinct().ToList(); evaluation.normalTouchedRows = evaluation.normalTouchedRows.Distinct().ToList(); //recalculateMode(evaluation); } }
public Form1() { InitializeComponent(); // initialize export button to be disabled button1.Enabled = false; // initialize Serial Initialize var ports = SerialPort.GetPortNames(); comComboBox.DataSource = ports; // initialize rows/columns seqDataGridView.DefaultCellStyle.SelectionForeColor = Color.Gray; seqDataGridView.RowCount = 4; seqDataGridView.AllowDrop = true; var columns = new DataGridViewCustomColumn[NUM_ROW_CELLS]; for (int i = 0; i < NUM_ROW_CELLS; i++) { columns[i] = new DataGridViewCustomColumn(); columns[i].Width = seqDataGridView.Rows[0].Height + 2; } //basePictureBox.Image = new Bitmap(@"D:\Desktop\Active HW\Senior Project\square_wave.png"); seqDataGridView.Columns.AddRange(columns); seqDataGridView.Columns.RemoveAt(0); //seqDataGridView.ColumnCount = 50; for (int r = 0; r < seqDataGridView.RowCount; r++) { for (int c = 0; c < seqDataGridView.ColumnCount; c++) { //Bitmap image = FLASH_IMAGE; //image.SetResolution(10, 10); DataGridViewCustomCell cell = (DataGridViewCustomCell)seqDataGridView.Rows[r].Cells[c]; cell.mode = "Fade"; seqDataGridView.Rows[r].Cells[c].Style.BackColor = Color.Black; } } // initial formating seqDataGridView.RowHeadersWidth = seqDataGridView.RowHeadersWidth + 8; seqDataGridView.Rows[0].HeaderCell.Value = "R"; seqDataGridView.Rows[1].HeaderCell.Value = "G"; seqDataGridView.Rows[2].HeaderCell.Value = "B"; seqDataGridView.Rows[3].HeaderCell.Value = "C"; seqDataGridView.AllowUserToResizeColumns = false; seqDataGridView.AllowUserToResizeRows = false; }
// export handler private void button1_Click_1(object sender, EventArgs e) { CellData[,] cells = new CellData[3, NUM_ROW_CELLS]; for (int row_i = 0; row_i < 3; row_i++) { DataGridViewRow row = seqDataGridView.Rows[row_i]; for (int cell_i = 0; cell_i < row.Cells.Count; cell_i++) { DataGridViewCustomCell customCell = (DataGridViewCustomCell)row.Cells[cell_i]; int rate = customCell.rate; string mode = customCell.mode; int[] intensities = new int[] { customCell.Style.BackColor.R, customCell.Style.BackColor.G, customCell.Style.BackColor.B }; cells[row_i, cell_i] = new CellData { rate = rate, mode = mode, intensity = intensities[row_i], color = row_i }; } } ExportClicked(cells); }
private void seqDataGridView_SelectionChanged(object sender, EventArgs e) { if (seqDataGridView.SelectedCells.Count > 1) { var selected = seqDataGridView.SelectedCells; bool isCRow = false; int selectedIndex = selected.Count - 1; DataGridViewCustomCell baseCell = (DataGridViewCustomCell)seqDataGridView.SelectedCells[seqDataGridView.SelectedCells.Count - 1]; if (selected[selectedIndex].Style.BackColor != seqDataGridView.DefaultCellStyle.BackColor) { if (selected[selectedIndex].RowIndex == 3) { isCRow = true; } foreach (DataGridViewCell c in seqDataGridView.SelectedCells) { // c.RowIndex == selected[selectedIndex].RowIndex DataGridViewCustomCell cell = (DataGridViewCustomCell)c; Color color = seqDataGridView.Rows[selected[selectedIndex].RowIndex].Cells[selected[selectedIndex].ColumnIndex].Style.BackColor; if (!isCRow) { if (cell.RowIndex == baseCell.RowIndex) { cell.Style.BackColor = baseCell.Style.BackColor;//color; cell.mode = baseCell.mode; cell.rate = baseCell.rate; } } else { int col = c.ColumnIndex; DataGridViewCustomCell redCell = (DataGridViewCustomCell)seqDataGridView.Rows[0].Cells[col]; DataGridViewCustomCell greenCell = (DataGridViewCustomCell)seqDataGridView.Rows[1].Cells[col]; DataGridViewCustomCell blueCell = (DataGridViewCustomCell)seqDataGridView.Rows[2].Cells[col]; DataGridViewCustomCell colorCell = (DataGridViewCustomCell)seqDataGridView.Rows[3].Cells[col]; redCell.Style.BackColor = Color.FromArgb(baseCell.Style.BackColor.R, 0, 0); redCell.mode = baseCell.mode; redCell.rate = baseCell.rate; greenCell.Style.BackColor = Color.FromArgb(0, baseCell.Style.BackColor.G, 0); greenCell.mode = baseCell.mode; greenCell.rate = baseCell.rate; blueCell.Style.BackColor = Color.FromArgb(0, 0, baseCell.Style.BackColor.B); blueCell.mode = baseCell.mode; blueCell.rate = baseCell.rate; colorCell.Style.BackColor = baseCell.Style.BackColor; colorCell.mode = baseCell.mode; colorCell.rate = baseCell.rate; /* * c.Style.BackColor = selected[selectedIndex].Style.BackColor; * seqDataGridView.Rows[0].Cells[col].Style.BackColor = Color.FromArgb(c.Style.BackColor.R, 0, 0); * seqDataGridView.Rows[1].Cells[col].Style.BackColor = Color.FromArgb(0, c.Style.BackColor.G, 0); * seqDataGridView.Rows[2].Cells[col].Style.BackColor = Color.FromArgb(0, 0, c.Style.BackColor.B); * seqDataGridView.Rows[3].Cells[col].Style.BackColor = color; */ } recalculateColor(c.RowIndex, c.ColumnIndex); } } } }