private void SetGrid() { int statusSpread = 2; grid.ColumnCount = statusSpread * 4 + 2; //grid ParameterDefinition[] componentDefinition = new ParameterDefinition[] { new ParameterDefinition("u1"), new ParameterDefinition("u2"), new ParameterDefinition("u3"), new ParameterDefinition("u4"), new ParameterDefinition("u5"), new ParameterDefinition("u6"), new ParameterDefinition("u7"), new ParameterDefinition("u8"), new ParameterDefinition("u9"), new ParameterDefinition("u10"), new ParameterDefinition("u11"), new ParameterDefinition("u10") }; for (int r = 0; r < 5; r++) { DataGridViewRow row = new DataGridViewRow(); Evel.engine.Component comp = new Evel.engine.Component(componentDefinition, false, false); int parameterId = 0; foreach (ParameterStatus status in MainForm.StatusColors.Keys) { for (int i = 0; i < statusSpread - ((status & ParameterStatus.Binding) > 0 ? 1 : 0); i++) { DataGridViewCell cell; if (r == 0) { cell = new DataGridViewComboBoxCell(); ((DataGridViewComboBoxCell)cell).DataSource = optionsStatusesSource; ((DataGridViewComboBoxCell)cell).ValueMember = "ValueMember"; ((DataGridViewComboBoxCell)cell).DisplayMember = "DisplayMember"; cell.Value = ((int)status).ToString(); cell.Style.BackColor = System.Drawing.SystemColors.ControlDark; cell.Style.SelectionBackColor = System.Drawing.SystemColors.ControlDark; cell.Style.Font = new Font(grid.Font, FontStyle.Bold); } else { IParameter parameter = comp[parameterId++]; parameter.Status = status; cell = new DataGridViewParameterCell(parameter); cell.Value = 0.2; } row.Cells.Add(cell); } } grid.Rows.Add(row); } //for (int c = 0; c < grid.ColumnCount; c++) // grid.Columns[c].Width = 70; }
public virtual DataGridViewParameterCell CreateParameterCell(IParameter parameter) { DataGridViewParameterCell cell = new DataGridViewParameterCell(parameter); //cell.UserValue = parameter.Value; if (parameter.Definition.Name.ToLower().Contains("int")) { cell.ConvertToUserValue += ConvertToUserIntensity; cell.ConvertFromUserValue += ConvertFromUserIntensity; } return(cell); }
//public override bool IsCellReadOnly(DataGridViewCell cell) { // bool result = base.IsCellReadOnly(cell); //if (cell.RowIndex == 1 // && cell is DataGridViewParameterCell // && groupDefinition.name.ToLower() == "prompt") { // IParameter parameter = ((DataGridViewParameterCell)cell).Parameter; // if (parameter.Definition.Name.ToLower() == "int" && !container.ParentProject.IsBusy) // //result = result || ((parameter.Status & ParameterStatus.Free) == ParameterStatus.Free); // result = false; //} // return result; //} public override DataGridViewParameterCell CreateParameterCell(IParameter parameter) { DataGridViewParameterCell cell = base.CreateParameterCell(parameter); if (parameter.Definition.Name.IndexOf("shift", StringComparison.CurrentCultureIgnoreCase) == -1) { //if (parameter.Definition.Name.IndexOf("int", StringComparison.CurrentCultureIgnoreCase) == -1) cell.ConvertToUserValue += Absolute; } //else { // cell.ConvertFromUserValue += ConvertFromUserShift; // cell.ConvertToUserValue += ConvertToUserShift; //} return(cell); }
//protected void ConvertToUserShift(ref double value) { // value /= container.Spectra[0].Constants[0]; //} //protected void ConvertFromUserShift(ref double value) { // value *= container.Spectra[0].Constants[0]; //} public override void CellFormatting(Object sender, DataGridViewCellFormattingEventArgs e) { if (groupDefinition.name.ToLower() == "prompt") { DataGridParameterView grid = (DataGridParameterView)sender; if (grid[e.ColumnIndex, e.RowIndex] is DataGridViewParameterCell) { IParameter parameter = ((DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex]).Parameter; if (parameter.HasReferenceValue || (e.RowIndex != 1 && spectra[0].Container.ParentProject.CalculatedValues && ((parameter.Status & (ParameterStatus.Local | ParameterStatus.Free)) == (ParameterStatus.Local | ParameterStatus.Free)))) { e.Value = "-"; grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } else { DataGridViewParameterCell cell = (DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex]; //e.Value = String.Format("{0:G05}", cell.Value); if (cell.UserError > (double)cell.Value || cell.UserError == 0) { e.Value = ((double)cell.Value).ToString("G05", numberFormat); } else if (cell.UserError > 0 && cell.UserError < 1) { e.Value = ((double)cell.Value).ToString(String.Format("F{0}", Math.Ceiling(Math.Abs(Math.Log10(cell.UserError))), numberFormat)); } else //if (cell.UserError > 1) { { e.Value = ((double)cell.Value).ToString("F0", numberFormat); } //} grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleLeft; } e.FormattingApplied = true; } if ((grid[e.ColumnIndex, e.RowIndex].ReadOnly = IsCellReadOnly(grid[e.ColumnIndex, e.RowIndex])) && e.ColumnIndex >= grid.FixedCols) { e.CellStyle.ForeColor = System.Drawing.Color.Black; } } else { base.CellFormatting(sender, e); } }
public override DataGridViewSpectrumRow CreateSpectrumRow(ISpectrum spectrum) { DataGridViewSpectrumRow result = base.CreateSpectrumRow(spectrum); if (GetColumnCount() > ((DataGridParameterView)gridView).FixedCols) { if (((groupDefinition.Type & GroupType.Contributet) == GroupType.Contributet) && ((groupDefinition.Type & GroupType.CalcContribution) != GroupType.CalcContribution)) { IParameter parameter = ((ContributedGroup)spectrum.Parameters[groupDefinition.name]).contribution; DataGridViewParameterCell cell = new DataGridViewParameterCell(parameter); //cell.UserValue = parameter.Value; //if source add special conversion of contribution if (groupDefinition.kind == 2) { cell.ConvertFromUserValue += new UserValueConversionHandler(ConvertFromUserSource); cell.ConvertToUserValue += new UserValueConversionHandler(ConvertToUserSource); } result.Cells.Add(cell); } } return(result); }
public virtual void CellFormatting(Object sender, DataGridViewCellFormattingEventArgs e) { DataGridParameterView grid = (DataGridParameterView)sender; if (e.Value != null) { if (grid[e.ColumnIndex, e.RowIndex] is DataGridViewParameterCell) { IParameter parameter = ((DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex]).Parameter; if ((parameter.HasReferenceValue && !(parameter.BindingParameter && e.RowIndex == 1)) || (e.RowIndex != 1 && spectra[0].Container.ParentProject.CalculatedValues && ((parameter.Status & (ParameterStatus.Local | ParameterStatus.Free)) == (ParameterStatus.Local | ParameterStatus.Free))) || (e.RowIndex == 1 && (parameter.Definition.Properties & ParameterProperties.ComponentIntensity) > 0 && spectra[0].Container.ParentProject.CalculatedValues && (parameter.Status & ParameterStatus.Free) == ParameterStatus.Free)) { e.Value = "-"; grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } else { DataGridViewParameterCell cell = (DataGridViewParameterCell)grid[e.ColumnIndex, e.RowIndex]; if (cell.UserError > (double)cell.Value || cell.UserError == 0 || double.IsNaN(cell.UserError) || double.IsInfinity(cell.UserError)) { e.Value = ((double)cell.Value).ToString("G06", numberFormat); } else if (cell.UserError > 0 && cell.UserError < 1) { e.Value = ((double)cell.Value).ToString(String.Format("F{0}", Math.Ceiling(Math.Abs(Math.Log10(cell.UserError))), numberFormat)); } else //if (cell.UserError > 1) { { e.Value = ((double)cell.Value).ToString("F0", numberFormat); } //} grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleLeft; } } else if (grid[e.ColumnIndex, e.RowIndex] is DataGridViewCustomValueCell) { //e.Value = e.Value.ToString("F3"); grid[e.ColumnIndex, e.RowIndex].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } else { if ((e.RowIndex == 0) && (e.ColumnIndex >= grid.FixedCols)) { if (e.Value is CellParameterStatus) { e.CellStyle.ForeColor = ((CellParameterStatus)e.Value).ValueColor; } } else { e.Value = e.Value.ToString(); } } e.FormattingApplied = true; } if ((grid[e.ColumnIndex, e.RowIndex].ReadOnly = IsCellReadOnly(grid[e.ColumnIndex, e.RowIndex])) && e.ColumnIndex >= grid.FixedCols) { e.CellStyle.ForeColor = Color.Black; } }
public virtual DataGridViewSpectrumRow CreateSpectrumRow(ISpectrum spectrum) { DataGridViewSpectrumRow spectrumRow = new DataGridViewSpectrumRow(spectrum); DataGridViewTextBoxCell spectrumcell = new DataGridViewTextBoxCell(); spectrumcell.Value = spectrum.Name; spectrumcell.Style.BackColor = System.Drawing.SystemColors.Control; //spectrumcell.ReadOnly = true; spectrumRow.Cells.Add(spectrumcell); //spectrumcell = new DataGridViewTextBoxCell(); DataGridViewParameterCell keyValueCell = CreateParameterCell(spectrum.Parameters[0].Components[0]["key value"]); keyValueCell.Style.BackColor = System.Drawing.SystemColors.Control; spectrumRow.Cells.Add(keyValueCell); if (FixedColCount == 3) { //dodatkowa kolumna z nazwa contenera spectrumcell = new DataGridViewTextBoxCell(); spectrumcell.Value = spectrum.Container.Name; spectrumcell.Style.BackColor = System.Drawing.SystemColors.Control; spectrumRow.Cells.Add(spectrumcell); } spectrumcell = new DataGridViewCustomValueCell(delegate(ISpectrum s) { if (double.IsInfinity(s.Fit) || double.IsNaN(s.Fit)) { return(" "); } else { return(s.Fit.ToString("F4")); } }); spectrumcell.Style.BackColor = System.Drawing.SystemColors.Control; spectrumRow.Cells.Add(spectrumcell); //spectrumcell.ReadOnly = true; foreach (IComponent component in spectrum.Parameters[groupDefinition.name].Components) { foreach (IParameter parameter in component) { //if (!parameter.Definition.Visible) continue; spectrumRow.Cells.Add(CreateParameterCell(parameter)); } } foreach (IParameter parameter in spectrum.Parameters[groupDefinition.name].GroupUniqueParameters) { spectrumRow.Cells.Add(CreateParameterCell(parameter)); } if (HasGraphicAdjustment) { DataGridViewButtonCell adjustButton = new DataGridViewButtonCell(); adjustButton.Value = "adjust..."; adjustButton.Style.Font = new Font("Arial", gridView.Font.Size); adjustButton.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; adjustButton.Style.ForeColor = System.Drawing.Color.Black; adjustButton.Style.SelectionForeColor = adjustButton.Style.ForeColor; adjustButton.Style.BackColor = System.Drawing.SystemColors.ButtonFace; adjustButton.Style.SelectionBackColor = adjustButton.Style.BackColor; adjustButton.FlatStyle = FlatStyle.Popup; adjustButton.ToolTipText = ""; spectrumRow.Cells.Add(adjustButton); spectrumcell = new DataGridViewCustomValueCell(delegate(ISpectrum s) { return(String.Format("{0:F3} mln", s.Statistic / 1e6)); }); spectrumcell.Style.BackColor = System.Drawing.SystemColors.Control; spectrumRow.Cells.Add(spectrumcell); } return(spectrumRow); }
//public static void DrawHeaderContent(string s, Graphics g, Font font, Rectangle rect, bool center, Brush brush) { // //if (e.Value == null) return; // string[] subs = s.Split(new char[] { '\0' }); //, StringSplitOptions.RemoveEmptyEntries); // int[] xOffset = new int[subs.Length]; // int[] yOffset = new int[subs.Length]; // Font[] fonts = new Font[subs.Length]; // int stringWidth = 0; // int topPadding = 3; // for (int i = 0; i < subs.Length; i++) { // //switch (subs[i][0]) { // if (subs[i].IndexOf("greek:") == 0) { // //case '@': // subs[i] = subs[i].Substring(6); // fonts[i] = new Font("Symbol", font.Size, FontStyle.Bold); // yOffset[i] = topPadding; // } else { // if (subs[i].IndexOf("sub:") == 0) { // subs[i] = subs[i].Substring(4); // fonts[i] = (i == 0) ? font : new Font(font.FontFamily, font.Size - 2, FontStyle.Bold); // yOffset[i] = topPadding + 5; // } else { // yOffset[i] = topPadding; // fonts[i] = new Font(font, FontStyle.Bold); // } // } // xOffset[i] = stringWidth - i * 2; // stringWidth += (int)g.MeasureString(subs[i], fonts[i], 1000, new StringFormat(StringFormatFlags.MeasureTrailingSpaces)).Width; // } // int x0; // if (center) { // x0 = rect.Left + (rect.Width - stringWidth) / 2; // } else { // x0 = rect.Left; // } // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; // for (int i = 0; i < subs.Length; i++) { // //g.DrawString(subs[i], fonts[i], brush, x0 + xOffset[i], rect.Top + yOffset[i]); // g.DrawString("R", SystemFonts.CaptionFont, SystemBrushes.ControlText, x0 + xOffset[i], rect.Top + yOffset[i]); // } //} protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == -1) { return; } //e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; //headers if ((e.RowIndex == -1) || this[e.ColumnIndex, e.RowIndex].FormattedValue.ToString().Contains("[p")) { e.Paint(e.ClipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.Border | DataGridViewPaintParts.Background); DefaultGroupGUI.DrawHeaderContent(e.Value.ToString(), e.Graphics, e.CellStyle.Font, e.CellBounds, e.CellStyle.Alignment == DataGridViewContentAlignment.MiddleCenter, Brushes.Black); e.Handled = true; } else { if (this[e.ColumnIndex, e.RowIndex] is DataGridViewParameterCell) { DataGridViewParameterCell cell = (DataGridViewParameterCell)this[e.ColumnIndex, e.RowIndex]; if ((cell.Parameter.Definition.Properties & ParameterProperties.KeyValue) == 0) { Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 2, e.CellBounds.Height - 2); Color backColor; //if (cell.Parameter.Expression != null) { // backColor = SystemColors.ButtonFace; //} else { if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected) { backColor = System.Drawing.SystemColors.Highlight; } else { backColor = (cell.ReadOnly) ? readonlyColor : e.CellStyle.BackColor; } //} using ( Brush gridBrush = new SolidBrush(GridColor), backColorBrush = new SolidBrush(backColor)) { IParameter referencedParameter = (cell.Parameter.HasReferenceValue) ? cell.Parameter.ReferencedParameter : cell.Parameter; using (Pen gridLinePen = new Pen(gridBrush), rectPen = new Pen(MainForm.GetColor(referencedParameter.Status))) { // Erase the cell. e.Graphics.FillRectangle(backColorBrush, newRect); //if partially referenced parameter draw a reference sign if (cell.Parameter.ReferenceGroup > 0) { e.Graphics.FillRectangle(ReferenceBrushes[(cell.Parameter.ReferenceGroup - 1) % ReferenceBrushes.Length], newRect.Right - 6, newRect.Top + 3, 4, newRect.Height - 5); } //min max lines if (!cell.Parameter.HasReferenceValue) { if (!double.IsPositiveInfinity(cell.Parameter.Maximum)) { e.Graphics.DrawLine(Pens.Black, newRect.Left + 3, newRect.Top + 3, newRect.Right - 3, newRect.Top + 3); } if (!double.IsNegativeInfinity(cell.Parameter.Minimum)) { e.Graphics.DrawLine(Pens.Black, newRect.Left + 3, newRect.Bottom - 3, newRect.Right - 3, newRect.Bottom - 3); } } // Draw the grid lines (only the right and bottom lines; // DataGridView takes care of the others). e.Graphics.DrawLine(Pens.White, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); e.Graphics.DrawLine(Pens.White, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom); // Draw the inset highlight box. e.Graphics.DrawRectangle(rectPen, newRect); // Draw the text content of the cell e.PaintContent(e.CellBounds); e.Handled = true; } } } } } }