private static TabGradient GetTabGradientFromControlGradient(ControlGradient controlGradient) { return(new TabGradient() { StartColor = controlGradient.StartColor, EndColor = controlGradient.EndColor, LinearGradientMode = controlGradient.LinearGradientMode, TextColor = controlGradient.TextColor }); }
private static void DrawExpanderButton(Graphics gfx, Rectangle bounds, ControlGradient expanderGradient, Pen hierarchyLinePen) { using (Brush brush = new LinearGradientBrush( bounds, expanderGradient.StartColor, expanderGradient.EndColor, expanderGradient.LinearGradientMode)) { gfx.FillRectangle(brush, bounds); gfx.DrawRectangle(hierarchyLinePen, bounds); } }
/// <summary> /// Constructor</summary> /// <param name="style">Style</param> /// <param name="owner">Owner</param> internal TheTreeListView(Style style, TreeListView owner) { m_style = style; m_owner = owner; OwnerDraw = true; base.DoubleBuffered = true; SetStyle(ControlStyles.OptimizedDoubleBuffer, true); MouseMove += ListTreeViewMouseMove; // for a workaround DrawColumnHeader += ListTreeViewDrawColumnHeader; DrawItem += ListTreeViewDrawItem; DrawSubItem += ListTreeViewDrawSubItem; // default colors & such BorderStyle = BorderStyle.Fixed3D; m_textColor = SystemColors.ControlText; m_modifiableTextColor = Color.Red; m_highlightTextColor = SystemColors.HighlightText; m_modifiableHighlightTextColor = SystemColors.ControlText; BackColor = SystemColors.ControlLightLight; m_disabledTextColor = SystemColors.GrayText; m_highlightBackColor = ((SolidBrush)SystemBrushes.Highlight).Color; m_disabledBackColor = ((SolidBrush)SystemBrushes.Control).Color; m_gridLinesColor = DefaultBackColor; m_expanderGradient = new ControlGradient { StartColor = Color.White, EndColor = Color.LightGray, LinearGradientMode = LinearGradientMode.Vertical }; m_expanderPen = Pens.Black; m_hierarchyLinePen = Pens.DarkGray; //m_columnHeaderGradient = // new ControlGradient // { // StartColor = Color.White, // EndColor = Color.FromArgb(255, 242, 243, 245), // LinearGradientMode = LinearGradientMode.Vertical, // TextColor = SystemColors.ControlText // }; //m_columnHeaderSeparatorColor = Color.FromArgb(255, 213, 213, 213); }
private static ControlGradient GetControlGradientFromDockPanelGradient(DockPanelGradient dockPanelGradient) { var controlGradient = new ControlGradient() { StartColor = dockPanelGradient.StartColor, EndColor = dockPanelGradient.EndColor, LinearGradientMode = dockPanelGradient.LinearGradientMode }; var tabGradient = dockPanelGradient as TabGradient; if (tabGradient != null) { controlGradient.TextColor = tabGradient.TextColor; } return(controlGradient); }
private static void DrawCollapser(Graphics gfx, Rectangle bounds, ControlGradient expanderGradient, Pen expanderPen, Pen hierarchyLinePen, bool bItemBelow) { const int iRectOffset = 5; const int iTwoTimesRectOffset = iRectOffset * 2; const int iLineOffset = 3; Point center = new Point( bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2)); // Rectangle around the "-" DrawExpanderButton( gfx, new Rectangle( center.X - iRectOffset, center.Y - iRectOffset, iTwoTimesRectOffset, iTwoTimesRectOffset), expanderGradient, hierarchyLinePen); // Horizontal line of the "-" gfx.DrawLine( expanderPen, center.X - iLineOffset, center.Y, center.X + iLineOffset, center.Y); if (!bItemBelow) { return; } // Vertical line below the rectangle // that connects to the item below gfx.DrawLine( hierarchyLinePen, center.X, center.Y + iRectOffset, center.X, bounds.Bottom); }
private static void DrawExpander(Graphics gfx, Rectangle bounds, ControlGradient expanderGradient, Pen expanderPen, Pen hierarchyLinePen) { const int iRectOffset = 5; const int iTwoTimesRectOffset = iRectOffset * 2; const int iLineOffset = 3; Point center = new Point( bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2)); // Rectangle around the "+" DrawExpanderButton( gfx, new Rectangle( center.X - iRectOffset, center.Y - iRectOffset, iTwoTimesRectOffset, iTwoTimesRectOffset), expanderGradient, hierarchyLinePen); // Horizontal line of the "+" gfx.DrawLine( expanderPen, center.X - iLineOffset, center.Y, center.X + iLineOffset, center.Y); // Vertical line of the "+" gfx.DrawLine( expanderPen, center.X, center.Y - iLineOffset, center.X, center.Y + iLineOffset); }
private static void DrawExtraneousStuff(DrawListViewSubItemEventArgs e, ref int iOffset, ControlGradient expanderGradient, Pen expanderPen, Pen hierarchyLinePen) { if (e.Item.Tag == null) { return; } // Not an item that requires expander/collapser // or hierarchy lines so bail if (!e.Item.Tag.Is <Node>()) { return; } // This node Node nodeThis = e.Item.Tag.As <Node>(); // Early out for special 'root' level items if (nodeThis.IsLeaf && (nodeThis.Level == 1)) { iOffset += ExtraneousItemWidth; return; } // Find out if there's a visible sibling node Node nodeSibling; FindSibling(nodeThis, out nodeSibling); bool bHasSibling = nodeSibling != null; // Find out if there's a visible child node Node nodeChild; FindChild(nodeThis, out nodeChild); bool bHasChild = nodeChild != null; // // Node levels start @ 1 not 0 // // From left to right start drawing any hierarchy // lines and/or collapser/expander images for (int i = 0; i < nodeThis.Level; i++) { // // Set stuff up for the current iteration // Point posCur = new Point(e.Item.Bounds.X + iOffset, e.Item.Bounds.Y); Size sizeCur = new Size(ExtraneousItemWidth, e.Item.Bounds.Height); Rectangle rectBounds = new Rectangle(posCur, sizeCur); // // Try to do some drawing // // Try and find an expanded item above us (tells us // what type of line we need to draw - if any) Node nodeRelative; FindExpandedRelativeAboveAtLevel(nodeThis, i + 1, out nodeRelative); if (nodeRelative != null) { if (nodeRelative == nodeThis.Parent) { DrawElbow(e.Graphics, rectBounds, hierarchyLinePen, bHasSibling); } } // Check for drawing vertical line(s) { bool bDrawVerticalLine = false; // Find ancestor that's one level above the "current" // (ie. i + 1) level and see if they have a sibling Node nodeTemp; FindExpandedRelativeAboveAtLevel(nodeThis, i + 2, out nodeTemp); if (nodeTemp != null) { Node nodeTempSibling; FindSibling(nodeTemp, out nodeTempSibling); if (nodeTempSibling != null) { bDrawVerticalLine = true; } } if (bDrawVerticalLine) { DrawVerticalLine(e.Graphics, rectBounds, hierarchyLinePen); } } // Check if need an expander/collapser bool bDrawExpanderCollapser = (i == (nodeThis.Level - 1)) && (nodeThis.HasChildren || !nodeThis.IsLeaf); // Draw expander/collapser if (bDrawExpanderCollapser) { if (nodeThis.Expanded) { DrawCollapser(e.Graphics, rectBounds, expanderGradient, expanderPen, hierarchyLinePen, bHasChild); } else { DrawExpander(e.Graphics, rectBounds, expanderGradient, expanderPen, hierarchyLinePen); } // Set the are that can be clicked nodeThis.HitRect = rectBounds; } // Check if horizontal line needed bool bDrawHorizontalLine = (i == (nodeThis.Level - 1)) && (i > 0) && !bDrawExpanderCollapser; if (bDrawHorizontalLine) { DrawHorizontalLine(e.Graphics, rectBounds, hierarchyLinePen); } // Keep indenting iOffset += ExtraneousItemWidth; } }