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 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 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); }
// 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); } } } }
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); }
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); }
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; } }