Exemplo n.º 1
0
 /// <summary>Prevents painting the editing controls for analysis parameter rows.</summary>
 void dataGridView_CellPainting(object sender, TreeDataGridViewCellPaintingEventArgs e)
 {
     if (e.RowIndexHierarchy.Count > 1 && e.ColumnIndex > 1)
     {
         e.PaintBackground(e.ClipBounds, e.State.HasFlag(DataGridViewElementStates.Selected));
         e.Handled = true;
     }
     else
     {
         e.Handled = false;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create symbols and/or images
        /// </summary>
        /// <param name="e"></param>
        protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
        {
            if (expandedRowList == null)
            {
                base.OnCellPainting(e);
                return;
            }


            //Only paint in the first column of each info-containing row
            if (e.RowIndex < 0 || e.ColumnIndex != 0)
            {
                if (CellPainting != null)
                {
                    var rowIndexHierarchy = e.RowIndex < 0 ? HeaderRowIndexHierarchy : expandedRowList[e.RowIndex].RowIndexHierarchy;
                    var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowIndexHierarchy);
                    CellPainting(this, e2);
                    if (e2.Handled)
                    {
                        e.Handled = true;
                        return;
                    }
                }

                base.OnCellPainting(e);
                return;
            }

            var rowInfo   = expandedRowList[e.RowIndex];
            int nodeDepth = rowInfo.RowIndexHierarchy.Count - 1;
            int iconWidth = 0;

            if (CellPainting != null)
            {
                var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowInfo.RowIndexHierarchy);
                CellPainting(this, e2);
                if (e2.Handled)
                {
                    e.Handled = true;
                    return;
                }
            }

            e.Handled = true;

            //Still show selection if row is selected
            bool isSelected = (e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected;

            e.PaintBackground(e.CellBounds, isSelected);

            Point symbolPoint = GetSymbolPoint(e.CellBounds, nodeDepth);

            //Draw symbol if row is not in bottom node
            if (rowInfo.HasChildRows)
            {
                var symbol = rowInfo.ExpandedChildRows.Count > 0 ? ExpandedSymbol : CollapsedSymbol;

                var smoothingMode = e.Graphics.SmoothingMode;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                //Go through and actually draw the stored symbol
                var brush = new SolidBrush(isSelected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
                var pen   = new Pen(brush);
                foreach (Symbol.Line line in symbol.Lines)
                {
                    Point lineStart = line.Start, lineEnd = line.End;
                    lineStart.Offset(symbolPoint.X, symbolPoint.Y);
                    lineEnd.Offset(symbolPoint.X, symbolPoint.Y);
                    e.Graphics.DrawLine(pen, lineStart, lineEnd);
                }
                e.Graphics.SmoothingMode = smoothingMode;
            }

            //Draw icon if one is selected
            if (CellIconNeeded != null)
            {
                var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, rowInfo.RowIndexHierarchy);
                CellIconNeeded(this, cellValueEventArgs);
                if (cellValueEventArgs.Value != null)
                {
                    var icon = (Image)cellValueEventArgs.Value;
                    e.Graphics.DrawImage(icon, symbolPoint.X + SymbolWidth + 5, symbolPoint.Y - 3, 15, 15);
                    iconWidth = 20; //Indicates icon was drawn
                }
            }

            //Paint cell info, taking previous images into account
            var indentPadding = new Padding(symbolPoint.X - e.CellBounds.X + SymbolWidth + iconWidth + 2, 0, 0, 0);

            e.CellStyle.Padding = indentPadding;
            e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground);
        }
Exemplo n.º 3
0
 /// <summary>Prevents painting the editing controls for analysis parameter rows.</summary>
 void dataGridView_CellPainting(object sender, TreeDataGridViewCellPaintingEventArgs e)
 {
     if (e.RowIndexHierarchy.Count > 1 && e.ColumnIndex > 1)
     {
         e.PaintBackground(e.ClipBounds, e.State.HasFlag(DataGridViewElementStates.Selected));
         e.Handled = true;
     }
     else
         e.Handled = false;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Create symbols and/or images
        /// </summary>
        /// <param name="e"></param>
        protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
        {
            if (expandedRowList == null)
            {
                base.OnCellPainting(e);
                return;
            }


            //Only paint in the first column of each info-containing row
            if (e.RowIndex < 0 || e.ColumnIndex != 0)
            {
                if (CellPainting != null)
                {
                    var rowIndexHierarchy = e.RowIndex < 0 ? HeaderRowIndexHierarchy : expandedRowList[e.RowIndex].RowIndexHierarchy;
                    var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowIndexHierarchy);
                    CellPainting(this, e2);
                    if (e2.Handled)
                    {
                        e.Handled = true;
                        return;
                    }
                }

                base.OnCellPainting(e);
                return;
            }
            
            var rowInfo = expandedRowList[e.RowIndex];
            int nodeDepth = rowInfo.RowIndexHierarchy.Count - 1;
            int iconWidth = 0;

            if (CellPainting != null)
            {
                var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowInfo.RowIndexHierarchy);
                CellPainting(this, e2);
                if (e2.Handled)
                {
                    e.Handled = true;
                    return;
                }
            }

            e.Handled = true;

            //Still show selection if row is selected
            bool isSelected = (e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected;
            e.PaintBackground(e.CellBounds, isSelected);

            Point symbolPoint = GetSymbolPoint(e.CellBounds, nodeDepth);

            //Draw symbol if row is not in bottom node
            if (rowInfo.HasChildRows)
            {
                var symbol = rowInfo.ExpandedChildRows.Count > 0 ? ExpandedSymbol : CollapsedSymbol;

                var smoothingMode = e.Graphics.SmoothingMode;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                //Go through and actually draw the stored symbol
                var brush = new SolidBrush(isSelected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
                var pen = new Pen(brush);
                foreach (Symbol.Line line in symbol.Lines)
                {
                    Point lineStart = line.Start, lineEnd = line.End;
                    lineStart.Offset(symbolPoint.X, symbolPoint.Y);
                    lineEnd.Offset(symbolPoint.X, symbolPoint.Y);
                    e.Graphics.DrawLine(pen, lineStart, lineEnd);
                }
                e.Graphics.SmoothingMode = smoothingMode;
            }

            //Draw icon if one is selected
            if (CellIconNeeded != null)
            {
                var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, rowInfo.RowIndexHierarchy);
                CellIconNeeded(this, cellValueEventArgs);
                if (cellValueEventArgs.Value != null)
                {
                    var icon = (Image)cellValueEventArgs.Value;
                    e.Graphics.DrawImage(icon, symbolPoint.X + SymbolWidth + 5, symbolPoint.Y - 3, 15, 15);
                    iconWidth = 20; //Indicates icon was drawn
                }
            }

            //Paint cell info, taking previous images into account
            var indentPadding = new Padding(symbolPoint.X - e.CellBounds.X + SymbolWidth + iconWidth + 2, 0, 0, 0);
            e.CellStyle.Padding = indentPadding;
            e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground);
        }