Exemplo n.º 1
0
        protected virtual void PaintNodeContent(TreeView control, TreeNode node, int visibleIndex, ControlPaintArgs args)
        {
            UserNode treeNodeNode = new UserNode(string.Empty, new[] { "Node", "TreeViewNode" });

            treeNodeNode.SetParent(new ControlNode(control));

            if (node.IsSelected)
            {
                treeNodeNode.AddState(NodeStates.Checked);
            }

            if (visibleIndex % 2 == 0)
            {
                treeNodeNode.AddClass("Even");
            }
            else
            {
                treeNodeNode.AddClass("Odd");
            }

            IRuleset treeNodeRuleset = args.StyleSheet.GetRuleset(treeNodeNode);

            Rectangle nodeRect       = node.Bounds;
            Rectangle backgroundRect = new Rectangle(nodeRect.X + 2, nodeRect.Y + 1, nodeRect.Width, nodeRect.Height - 1);
            Rectangle textRect       = new Rectangle(nodeRect.X + 1, nodeRect.Y + 3, nodeRect.Width - 1, nodeRect.Height - 3);

            if (control.FullRowSelect)
            {
                backgroundRect = new Rectangle(0, backgroundRect.Y, control.Width, backgroundRect.Height);
            }

            args.StyleRenderer.PaintBackground(args.Graphics, backgroundRect, treeNodeRuleset);
            args.StyleRenderer.PaintText(args.Graphics, textRect, treeNodeRuleset, node.Text, control.Font, TextFormatFlags.Default | TextFormatFlags.VerticalCenter);
            args.StyleRenderer.PaintBorder(args.Graphics, backgroundRect, treeNodeRuleset);
        }
        // Private members

        private void PaintDropDownArrow(ComboBox control, ControlPaintArgs e)
        {
            INode    controlNode       = new ControlNode(control);
            UserNode dropDownArrowNode = new UserNode(string.Empty, new[] { "DropDownArrow" });

            dropDownArrowNode.SetParent(controlNode);
            dropDownArrowNode.SetStates(controlNode.States);

            IRuleset ruleset = e.StyleSheet.GetRuleset(dropDownArrowNode);

            // Create the arrow rectangle to match the bounds of the default control.

            Rectangle clientRect = control.ClientRectangle;
            Rectangle arrowRect  = new Rectangle(clientRect.Right - 12, clientRect.Y + 9, 7, 6);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            using (Pen pen = new Pen(ruleset.Color?.Value ?? SystemColors.ControlText)) {
                pen.Width     = 2.0f;
                pen.Alignment = PenAlignment.Center;
                pen.StartCap  = LineCap.Flat;
                pen.EndCap    = LineCap.Flat;

                PointF bottomMidpoint = new PointF(arrowRect.Left + arrowRect.Width / 2.0f, arrowRect.Bottom - 1);

                e.Graphics.DrawLine(pen, new PointF(arrowRect.Left, arrowRect.Top), bottomMidpoint);
                e.Graphics.DrawLine(pen, new PointF(arrowRect.Right, arrowRect.Top), bottomMidpoint);
            }
        }
Exemplo n.º 3
0
        private void PaintSubItem(Graphics graphics, ListViewItem item, ListViewItem.ListViewSubItem subItem)
        {
            ListView     listView     = item.ListView;
            ColumnHeader columnHeader = listView.Columns[item.SubItems.IndexOf(subItem)];

            Rectangle bounds = subItem.Bounds;
            UserNode  node   = new UserNode(bounds, listView.PointToClient(Cursor.Position));

            node.SetClass("ListViewItem");
            node.AddClass("Item");
            node.SetParent(new ControlNode(listView));

            if (item.Selected)
            {
                node.AddState(NodeStates.Checked);
            }

            int textPadding = 4;

            IRuleset ruleset = styleSheet.GetRuleset(node);

            Rectangle itemRect = new Rectangle(bounds.X, bounds.Y, columnHeader.Width, bounds.Height);
            Rectangle textRect = new Rectangle(itemRect.X + textPadding, itemRect.Y, itemRect.Width - textPadding * 2, itemRect.Height);

            TextFormatFlags textFormatFlags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix;

            styleRenderer.PaintText(graphics, textRect, ruleset, subItem.Text, subItem.Font, textFormatFlags);
            styleRenderer.PaintBorder(graphics, itemRect, ruleset);
        }
Exemplo n.º 4
0
        private void PaintItem(Graphics graphics, ListViewItem item)
        {
            Rectangle bounds = item.Bounds;
            UserNode  node   = new UserNode(bounds, item.ListView.PointToClient(Cursor.Position));

            node.AddClass("ListViewItem");
            node.AddClass("Item");
            node.SetParent(new ControlNode(item.ListView));

            if (item.Index % 2 == 0)
            {
                node.AddClass("Even");
            }
            else
            {
                node.AddClass("Odd");
            }

            if (item.Selected)
            {
                node.AddState(NodeStates.Checked);
            }

            IRuleset  ruleset = styleSheet.GetRuleset(node);
            Rectangle rect    = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);

            styleRenderer.PaintBackground(graphics, rect, ruleset);
            styleRenderer.PaintBorder(graphics, rect, ruleset);
        }
        private INode GetProgressNode(ProgressBar control)
        {
            UserNode node = new UserNode(string.Empty, new[] { "Progress" });

            node.SetParent(new ControlNode(control));

            return(node);
        }
Exemplo n.º 6
0
        private IRuleset GetToolStripSeparatorRuleset(ToolStrip parent)
        {
            UserNode node = getToolStripSeparatorNode();

            node.SetParent(new ControlNode(parent));

            return(styleSheet.GetRuleset(node));
        }
Exemplo n.º 7
0
        private IRuleset GetToolStripDropDownRuleset(ToolStrip parent)
        {
            UserNode node = GetToolStripDropDownNode();

            node.SetParent(new ControlNode(parent));

            return(styleSheet.GetRuleset(node));
        }
Exemplo n.º 8
0
        private IRuleset GetToolStripItemRuleset(ToolStrip parent, ToolStripItem item)
        {
            UserNode node = GetToolStripItemNode(item);

            node.SetParent(new ControlNode(parent));

            return(styleSheet.GetRuleset(node));
        }
Exemplo n.º 9
0
        private void PaintLines(TreeView control, TreeNodeCollection nodes, ControlPaintArgs args)
        {
            const int buttonWidth = 9;

            if (control.ShowLines && control.Nodes.Count > 0)
            {
                if (control.ShowRootLines || nodes[0].Level != 0)
                {
                    UserNode lineNode = new UserNode(string.Empty, new[] { "Lines" });

                    lineNode.SetParent(new ControlNode(control));

                    IRuleset lineRuleset = args.StyleSheet.GetRuleset(lineNode);

                    Color lineColor = lineRuleset.Color?.Value ?? Color.Black;

                    using (Pen linePen = new Pen(lineColor)) {
                        linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

                        // Draw a line from the first node down to the last node.

                        TreeNode firstNode = nodes[0];
                        TreeNode lastNode  = nodes[nodes.Count - 1];

                        int x1 = firstNode.Bounds.X - 8;
                        int x2 = x1;
                        int y1 = firstNode.Bounds.Y + (firstNode.Nodes.Count > 0 ? buttonWidth - 1 : 2);
                        int y2 = lastNode.Bounds.Y + (firstNode.Nodes.Count > 0 ? buttonWidth - 1 : 13);

                        args.Graphics.DrawLine(linePen, new Point(x1, y1), new Point(x2, y2));

                        // Draw horizontal lines connecting the vertical line to each of the nodes.

                        foreach (TreeNode childNode in nodes)
                        {
                            x1 = firstNode.Bounds.X - buttonWidth + 1;
                            x2 = childNode.Bounds.X + 2;
                            y1 = childNode.Bounds.Y + 12;
                            y2 = y1;

                            args.Graphics.DrawLine(linePen, new Point(x1, y1), new Point(x2, y2));
                        }
                    }
                }

                // Draw lines for the child nodes.

                foreach (TreeNode node in nodes)
                {
                    if (node.IsExpanded)
                    {
                        PaintLines(control, node.Nodes, args);
                    }
                }
            }
        }
Exemplo n.º 10
0
        // Private members

        private void PaintTabs(TabControl control, ControlPaintArgs e)
        {
            if (control.TabPages.Count > 0)
            {
                for (int i = 0; i < control.TabPages.Count; ++i)
                {
                    TabPage   tabPage = control.TabPages[i];
                    Rectangle tabRect = control.GetTabRect(i);
                    UserNode  tabNode = new UserNode(tabRect, control.PointToClient(Cursor.Position));

                    tabNode.SetParent(new ControlNode(control));
                    tabNode.AddClass("tab");

                    if (i == 0)
                    {
                        tabRect = new Rectangle(tabRect.X + 2, tabRect.Y, tabRect.Width - 2, tabRect.Height);
                    }

                    if (control.SelectedIndex == i)
                    {
                        // Draw selected tab.

                        tabNode.AddState(NodeStates.Checked);

                        IRuleset tabRuleset = e.StyleSheet.GetRuleset(tabNode);

                        Rectangle drawRect = new Rectangle(tabRect.X - 2, tabRect.Y - 2, tabRect.Width + 2, tabRect.Height + 4);
                        Rectangle textRect = new Rectangle(tabRect.X, tabRect.Y - 2, tabRect.Width, tabRect.Height);

                        if (i == 0)
                        {
                            drawRect = new Rectangle(drawRect.X + 2, drawRect.Y, drawRect.Width - 2, drawRect.Height);
                        }

                        e.StyleRenderer.PaintBackground(e.Graphics, drawRect, tabRuleset);
                        e.StyleRenderer.PaintBorder(e.Graphics, drawRect, tabRuleset);
                        e.StyleRenderer.PaintText(e.Graphics, textRect, tabRuleset, tabPage.Text, control.Font, textFormatFlags: TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                    }
                    else
                    {
                        // Draw unselected tab.

                        IRuleset tabRuleset = e.StyleSheet.GetRuleset(tabNode);

                        Rectangle drawRect = new Rectangle(tabRect.X, tabRect.Y, tabRect.Width, tabRect.Height + 2);

                        e.StyleRenderer.PaintBackground(e.Graphics, drawRect, tabRuleset);
                        e.StyleRenderer.PaintBorder(e.Graphics, drawRect, tabRuleset);
                        e.StyleRenderer.PaintText(e.Graphics, tabRect, tabRuleset, tabPage.Text, control.Font, textFormatFlags: TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                    }
                }
            }
        }
Exemplo n.º 11
0
        protected virtual void PaintNodeButton(TreeView control, TreeNode node, ControlPaintArgs args)
        {
            const int buttonWidth   = 9;
            const int detailPadding = 2;

            UserNode nodeButtonNode = new UserNode(string.Empty, new[] { "Button" });

            nodeButtonNode.SetParent(new ControlNode(control));

            if (node.IsSelected)
            {
                nodeButtonNode.AddState(NodeStates.Checked);
            }

            IRuleset nodeButtonRuleset = args.StyleSheet.GetRuleset(nodeButtonNode);

            Rectangle nodeRect   = node.Bounds;
            Rectangle buttonRect = new Rectangle(nodeRect.X - buttonWidth - 3, nodeRect.Y + nodeRect.Height - buttonWidth - 1, buttonWidth, buttonWidth);

            args.StyleRenderer.PaintBackground(args.Graphics, buttonRect, nodeButtonRuleset);
            args.StyleRenderer.PaintBorder(args.Graphics, buttonRect, nodeButtonRuleset);

            if (PaintNodeButtonContent)
            {
                Color detailColor = nodeButtonRuleset.Color?.Value ?? Color.Black;

                buttonRect.Inflate(-detailPadding, -detailPadding);

                int x    = buttonRect.X;
                int y    = buttonRect.Y;
                int x2   = x + buttonRect.Width - 1;
                int y2   = y + buttonRect.Height - 1;
                int midX = x + (buttonRect.Width / 2);
                int midY = y + (buttonRect.Height / 2);

                using (Pen detailPen = new Pen(detailColor)) {
                    args.Graphics.DrawLine(detailPen, new Point(x, midY), new Point(x2, midY));

                    if (!node.IsExpanded)
                    {
                        args.Graphics.DrawLine(detailPen, new Point(midX, y), new Point(midX, y2));
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void PaintCheck(CheckBox control, ControlPaintArgs e)
        {
            INode    controlNode = new ControlNode(control);
            UserNode checkNode   = new UserNode(string.Empty, new[] { "Check" });

            checkNode.SetParent(controlNode);
            checkNode.SetStates(controlNode.States);

            IRuleset parentRuleset = e.StyleSheet.GetRuleset(control);
            IRuleset ruleset       = e.StyleSheet.GetRuleset(checkNode, inherit: false);

            if (!ruleset.Any())
            {
                ruleset = CreateDefaultCheckRuleset();
            }

            ruleset.InheritProperties(parentRuleset);

            Rectangle clientRect = e.Control.ClientRectangle;
            Rectangle checkRect  = new Rectangle(clientRect.X, clientRect.Y + (int)(clientRect.Height / 2.0f - CheckWidth / 2.0f) - 1, CheckWidth, CheckWidth);

            e.StyleRenderer.PaintBackground(e.Graphics, checkRect, ruleset);
            e.StyleRenderer.PaintBorder(e.Graphics, checkRect, ruleset);

            // Draw the checkmark.

            if (control.Checked)
            {
                using (Pen pen = new Pen(ruleset.Color?.Value ?? SystemColors.ControlText)) {
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                    pen.Alignment = PenAlignment.Center;
                    pen.Width     = 2.0f;
                    pen.StartCap  = LineCap.Square;
                    pen.EndCap    = LineCap.Square;

                    e.Graphics.DrawLine(pen, checkRect.X + 3, checkRect.Y + checkRect.Height / 2.0f, checkRect.X + checkRect.Width / 2.0f - 1, checkRect.Y + checkRect.Height - 5);
                    e.Graphics.DrawLine(pen, checkRect.X + checkRect.Width / 2.0f - 1, checkRect.Y + checkRect.Height - 5, checkRect.X + checkRect.Width - 4, checkRect.Y + 3);
                }
            }
        }
Exemplo n.º 13
0
        private INode CreateItemNode(ListBox control, int itemindex)
        {
            object    item     = control.Items[itemindex];
            Rectangle itemRect = control.GetItemRectangle(itemindex);

            NodeStates states = NodeStates.None;

            if (control.SelectedItems.Contains(item))
            {
                states |= NodeStates.Checked;
            }

            if (ControlUtilities.MouseIntersectsWith(control, itemRect))
            {
                if (Control.MouseButtons.HasFlag(MouseButtons.Left))
                {
                    states |= NodeStates.Active;
                }
                else
                {
                    states |= NodeStates.Hover;
                }
            }

            UserNode node = new UserNode(string.Empty, new[] { "ListBoxItem", "Item" });

            node.SetParent(new ControlNode(control));
            node.SetStates(states);

            if (itemindex % 2 == 0)
            {
                node.AddClass("even");
            }
            else
            {
                node.AddClass("odd");
            }

            return(node);
        }
Exemplo n.º 14
0
        private UserNode GetColumnHeaderNode(ColumnHeader columnHeader)
        {
            Rectangle bounds = GetColumnHeaderBounds(columnHeader);

            UserNode node = new UserNode(bounds, columnHeader.ListView.PointToClient(Cursor.Position));

            node.SetParent(new ControlNode(columnHeader.ListView));

            node.AddClass("ColumnHeader");
            node.AddClass("Header");

            if (columnHeader.Index % 2 == 0)
            {
                node.AddClass("Even");
            }
            else
            {
                node.AddClass("Odd");
            }

            return(node);
        }
        private void PaintCheck(RadioButton control, ControlPaintArgs e)
        {
            INode    controlNode = new ControlNode(control);
            UserNode checkNode   = new UserNode(string.Empty, new[] { "Check" });

            checkNode.SetParent(controlNode);
            checkNode.SetStates(controlNode.States);

            IRuleset parentRuleset = e.StyleSheet.GetRuleset(control);
            IRuleset ruleset       = e.StyleSheet.GetRuleset(checkNode, inherit: false);

            if (!ruleset.Any())
            {
                ruleset = CreateDefaultCheckRuleset();
            }

            ruleset.InheritProperties(parentRuleset);

            Rectangle clientRect = control.ClientRectangle;
            Rectangle checkRect  = new Rectangle(clientRect.X, clientRect.Y + (int)(clientRect.Height / 2.0f - CheckWidth / 2.0f), CheckWidth, CheckWidth);

            e.StyleRenderer.PaintBackground(e.Graphics, checkRect, ruleset);
            e.StyleRenderer.PaintBorder(e.Graphics, checkRect, ruleset);

            // Draw the checkmark.

            if (control.Checked)
            {
                using (Brush brush = new SolidBrush(ruleset.Color?.Value ?? SystemColors.ControlText)) {
                    e.Graphics.SmoothingMode   = SmoothingMode.AntiAlias;
                    e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                    checkRect.Inflate(-3, -3);

                    e.Graphics.FillEllipse(brush, checkRect);
                }
            }
        }
        public void CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (sender is DataGridView dataGridView)
            {
                bool isColumnHeader = DataGridViewUtilities.IsColumnHeaderIndex(e.RowIndex);
                bool isRowHeader    = DataGridViewUtilities.IsRowHeaderIndex(e.ColumnIndex);
                bool isHeader       = isColumnHeader || isRowHeader;
                bool isSelected     = e.State.HasFlag(DataGridViewElementStates.Selected);

                UserNode cellNode = new UserNode(e.CellBounds, dataGridView.PointToClient(Cursor.Position));

                cellNode.AddClass("Cell");
                cellNode.SetParent(new ControlNode(sender as DataGridView));

                if (isColumnHeader)
                {
                    cellNode.AddClass("ColumnHeader");
                }
                else if (isRowHeader)
                {
                    cellNode.AddClass("RowHeader");
                }

                if (isHeader)
                {
                    cellNode.AddClass("Header");
                }

                if (e.RowIndex % 2 == 0)
                {
                    cellNode.AddClass("Even");
                }
                else
                {
                    cellNode.AddClass("Odd");
                }

                if (isSelected)
                {
                    cellNode.AddState(NodeStates.Checked);
                }

                IRuleset ruleset = styleSheet.GetRuleset(cellNode);

                if (RespectNonDefaultCellColors)
                {
                    ruleset = SetNonDefaultCellColors(ruleset, dataGridView, e);
                }

                if (ruleset.Color.HasValue())
                {
                    if (isSelected)
                    {
                        e.CellStyle.SelectionForeColor = ruleset.Color.Value;
                    }
                    else
                    {
                        e.CellStyle.ForeColor = ruleset.Color.Value;
                    }
                }

                if (ruleset.BackgroundColor.HasValue())
                {
                    if (isSelected)
                    {
                        e.CellStyle.SelectionBackColor = ruleset.BackgroundColor.Value;
                    }
                    else
                    {
                        e.CellStyle.BackColor = ruleset.BackgroundColor.Value;
                    }
                }

                if (ruleset.Opacity.HasValue() && ruleset.Opacity.Value < 1.0f)
                {
                    // Draw the part of the DataGridView background behind the cell.

                    styleRenderer.PaintParentBackground(e.Graphics, e.CellBounds, dataGridView.ClientRectangle, styleSheet.GetRuleset(dataGridView));
                }

                styleRenderer.PaintBackground(e.Graphics, e.CellBounds, ruleset);

                e.PaintContent(e.ClipBounds);

                styleRenderer.PaintBorder(e.Graphics, e.CellBounds, ruleset);

                e.Handled = true;
            }
        }