Пример #1
0
        public virtual void PaintCellBackground(Graphics dc,
                                                Rectangle cellRect,
                                                Node node,
                                                TreeListColumn column,
                                                TreeList.TextFormatting format,
                                                object data)
        {
            Color c = Color.Transparent;

            Point mousePoint = m_owner.PointToClient(Cursor.Position);
            Node  hoverNode  = m_owner.CalcHitNode(mousePoint);

            if (format.BackColor != Color.Transparent)
            {
                c = format.BackColor;
            }

            if (!m_owner.NodesSelection.Contains(node) && m_owner.FocusedNode != node &&
                !(hoverNode == node && m_owner.RowOptions.HoverHighlight) &&
                node.DefaultBackColor != Color.Transparent)
            {
                c = node.DefaultBackColor;
            }

            if (node.BackColor != Color.Transparent && !m_owner.NodesSelection.Contains(node) && m_owner.SelectedNode != node)
            {
                c = node.BackColor;
            }

            if (column.Index < node.IndexedBackColor.Length && node.IndexedBackColor[column.Index] != Color.Transparent)
            {
                c = node.IndexedBackColor[column.Index];
            }

            if (c != Color.Transparent)
            {
                Rectangle r = cellRect;
                r.X     -= Math.Max(0, column.CalculatedRect.Width - cellRect.Width);
                r.Width += Math.Max(0, column.CalculatedRect.Width - cellRect.Width);
                SolidBrush brush = new SolidBrush(c);
                dc.FillRectangle(brush, r);
                brush.Dispose();
            }
        }
Пример #2
0
        public virtual void PaintCellPlusMinus(Graphics dc, Rectangle glyphRect, Node node, TreeListColumn column, TreeList.TextFormatting format)
        {
            if (!Application.RenderWithVisualStyles)
            {
                // find square rect first
                int diff = glyphRect.Height - glyphRect.Width;
                glyphRect.Y      += diff / 2;
                glyphRect.Height -= diff;

                // draw 8x8 box centred
                while (glyphRect.Height > 8)
                {
                    glyphRect.Height -= 2;
                    glyphRect.Y      += 1;
                    glyphRect.X      += 1;
                }

                // make a box
                glyphRect.Width = glyphRect.Height;

                // clear first
                SolidBrush brush = new SolidBrush(format.BackColor);
                if (format.BackColor == Color.Transparent)
                {
                    brush = new SolidBrush(m_owner.BackColor);
                }
                dc.FillRectangle(brush, glyphRect);
                brush.Dispose();

                // draw outline
                Pen p = new Pen(SystemColors.ControlDark);
                dc.DrawRectangle(p, glyphRect);
                p.Dispose();

                p = new Pen(SystemColors.ControlText);

                // reduce box for internal lines
                glyphRect.X     += 2; glyphRect.Y += 2;
                glyphRect.Width -= 4; glyphRect.Height -= 4;

                // draw horizontal line always
                dc.DrawLine(p, glyphRect.X, glyphRect.Y + glyphRect.Height / 2, glyphRect.X + glyphRect.Width, glyphRect.Y + glyphRect.Height / 2);

                // draw vertical line if this should be a +
                if (!node.Expanded)
                {
                    dc.DrawLine(p, glyphRect.X + glyphRect.Width / 2, glyphRect.Y, glyphRect.X + glyphRect.Width / 2, glyphRect.Y + glyphRect.Height);
                }

                p.Dispose();
                return;
            }

            VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Closed;

            if (node.Expanded)
            {
                element = VisualStyleElement.TreeView.Glyph.Opened;
            }

            if (VisualStyleRenderer.IsElementDefined(element))
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(dc, glyphRect);
            }
        }
Пример #3
0
        public virtual void PaintCellText(Graphics dc,
                                          Rectangle cellRect,
                                          Node node,
                                          TreeListColumn column,
                                          TreeList.TextFormatting format,
                                          object data)
        {
            if (data != null)
            {
                cellRect = AdjustRectangle(cellRect, format.Padding);
                //dc.DrawRectangle(Pens.Black, cellRect);

                Color color = format.ForeColor;
                if (node.ForeColor != Color.Transparent)
                {
                    color = node.ForeColor;
                }
                if (m_owner.FocusedNode == node && Application.RenderWithVisualStyles == false && m_owner.Focused)
                {
                    color = SystemColors.HighlightText;
                }
                TextFormatFlags flags = TextFormatFlags.EndEllipsis | format.GetFormattingFlags();

                Font f           = m_owner.Font;
                Font disposefont = null;

                if (node.Bold && node.Italic)
                {
                    disposefont = f = new Font(f, FontStyle.Bold | FontStyle.Italic);
                }
                else if (node.Bold)
                {
                    disposefont = f = new Font(f, FontStyle.Bold);
                }
                else if (node.Italic)
                {
                    disposefont = f = new Font(f, FontStyle.Italic);
                }

                string datastring = "";

                if (m_converter != null)
                {
                    datastring = m_converter(column, data);
                }
                else
                {
                    datastring = data.ToString();
                }

                TextRenderer.DrawText(dc, datastring, f, cellRect, color, flags);

                Size sz = TextRenderer.MeasureText(dc, datastring, f, new Size(1000000, 10000), flags);

                int treecolumn = node.TreeColumn;
                if (treecolumn < 0)
                {
                    treecolumn = node.OwnerView.TreeColumn;
                }

                if (column.Index == treecolumn)
                {
                    node.ClippedText = (sz.Width > cellRect.Width || sz.Height > cellRect.Height);
                }

                if (disposefont != null)
                {
                    disposefont.Dispose();
                }
            }
        }