/// <summary> /// Paint the background of the node /// </summary> /// <param name="oNode"></param> /// <param name="oNodeRect"></param> private void PaintNodeBackground(Node oNode, Graphics oGraphics, Rectangle oNodeRect) { // if the node is selected node, then draw the selection if (oNode.IsSelected == true && m_oTreeView.HideSelection == false) { int nScrollWidth = 2; int nAdd = 0; if (oNode.GetCheckBoxes() == true && oNode.CheckBoxVisible == true) { //if (oNode.GetShowPlusMinus() == false) // nAdd = -2; //else nAdd = -1; } nScrollWidth += m_oTreeView.GetScrollBarWidth(); m_oBrush.Color = oNode.GetSelectedBorderColor(); // if full row select if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null) { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 1 + nAdd, oNodeRect.Y - 1, Width - (oNodeRect.X + 3) - nScrollWidth - nAdd, oNodeRect.Height - 1); m_oBrush.Color = oNode.GetSelectedBackColor(); if (oNode.GetSelectedFillStyle() == FillStyle.Flat) { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3); } else if (oNode.GetSelectedFillStyle() == FillStyle.HorizontalFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.HorizontalFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VerticalFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.VerticalFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.DiagonalBackward) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.DiagonalBackward, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.DiagonalForward) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.DiagonalForward, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VistaFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.VistaFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VerticalCentreFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 5) - nScrollWidth - nAdd, oNodeRect.Height - 3, FillStyle.VerticalCentreFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } } else { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 1 + nAdd, oNodeRect.Y - 1, (int)oNodeRect.Width, oNodeRect.Height - 1); m_oBrush.Color = oNode.GetSelectedBackColor(); if (oNode.GetSelectedFillStyle() == FillStyle.Flat) { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3); } else if (oNode.GetSelectedFillStyle() == FillStyle.HorizontalFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.HorizontalFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VerticalFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.VerticalFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.DiagonalBackward) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.DiagonalBackward, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.DiagonalForward) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.DiagonalForward, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VistaFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.VistaFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } else if (oNode.GetSelectedFillStyle() == FillStyle.VerticalCentreFading) { AreaPainter.PaintRectangle(oGraphics, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 2, oNodeRect.Height - 3, FillStyle.VerticalCentreFading, m_oBrush.Color, Color.White, BorderStyle.None, Color.Transparent); } } } // draw the focus rectangle if (oNode.IsSelected == true && oNode.TreeView.m_bUserFocus == true && oNode.TreeView.FocusNode == oNode && oNode.TreeView.FocusRectangle == true) { int nScrollWidth = 2; int nAdd = 0; nScrollWidth += m_oTreeView.GetScrollBarWidth(); if (oNode.GetCheckBoxes() == true && oNode.CheckBoxVisible == true) { //if (oNode.GetShowPlusMinus() == false) // nAdd = -2; //else nAdd = -1; } Pen oRectPen = new Pen(Color.Black, 1); oRectPen.DashStyle = DashStyle.Dot; if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null) { oGraphics.DrawRectangle(oRectPen, oNodeRect.X + 2 + nAdd, oNodeRect.Y, Width - (oNodeRect.X + 6) - nScrollWidth - nAdd, oNodeRect.Height - 4); } else { oGraphics.DrawRectangle(oRectPen, oNodeRect.X + 2 + nAdd, oNodeRect.Y, (int)oNodeRect.Width - 3, oNodeRect.Height - 4); } oRectPen.Dispose(); } // if not selected if (oNode.IsSelected == false) { // when draging the mouse over nodes, test if the node is being highlighted if (oNode == oNode.TreeView.HighlightedNode) { int nScrollWidth = 2; nScrollWidth += m_oTreeView.GetScrollBarWidth(); m_oBrush.Color = oNode.GetHighlightedBackColor(); if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null) { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 1, oNodeRect.Y - 1, Width - (oNodeRect.X + 3) - nScrollWidth, oNodeRect.Height - 1); } else { oGraphics.FillRectangle(m_oBrush, oNodeRect.X + 1, oNodeRect.Y - 1, (int)oNodeRect.Width, oNodeRect.Height - 1); } } } }
/// <summary> /// Paints the underline for the specified node /// </summary> /// <param name="oNode"></param> /// <param name="oGraphics"></param> /// <param name="nX"></param> /// <param name="nY"></param> private void PaintNodeUnderline(Node oNode, string sText, Graphics oGraphics, int nX, int nY) { UnderlineStyle oStyle = oNode.GetUnderlineStyle(); Pen oPen = new Pen(oNode.GetUnderlineColor(), 1); SizeF oSize = oGraphics.MeasureString(StringDrawUtils.GetInstance().GetTextFromFormattedString(sText), oNode.GetFont(), oNode.GetTreeView().GetDrawWidth() - nX - 8); oSize.Width += 2; if (oStyle == UnderlineStyle.Tilde) { Pen oClearPen = null; if (oNode.IsSelected == false) { if (oNode.BackgroundStyle.Visible == false) oClearPen = oNode.GetUnderlineBackColor(); else oClearPen = new Pen(oNode.BackgroundStyle.BackColor, 1); } else oClearPen = new Pen(oNode.GetSelectedBackColor(), 1); int nStep = 0; while (nX + 4 + nStep < nX + oSize.Width) { oGraphics.DrawLine(oPen, nX + 4 + nStep, nY + oSize.Height - 2, nX + 5 + nStep, nY + oSize.Height - 2); oGraphics.DrawLine(oClearPen, nX + 5 + nStep, nY + oSize.Height - 2, nX + 6 + nStep, nY + oSize.Height - 2); nStep += 4; } nStep = 0; while (nX + 4 + nStep < nX + oSize.Width) { oGraphics.DrawLine(oPen, nX + 5 + nStep, nY + oSize.Height - 1, nX + 6 + nStep, nY + oSize.Height - 1); oGraphics.DrawLine(oClearPen, nX + 6 + nStep, nY + oSize.Height - 1, nX + 7 + nStep, nY + oSize.Height - 1); nStep += 2; } nStep = 0; while (nX + 4 + nStep < nX + oSize.Width) { oGraphics.DrawLine(oPen, nX + 6 + nStep, nY + oSize.Height, nX + 7 + nStep, nY + oSize.Height); oGraphics.DrawLine(oClearPen, nX + 7 + nStep, nY + oSize.Height, nX + 8 + nStep, nY + oSize.Height); nStep += 4; } oClearPen.Dispose(); } else { if (oStyle == UnderlineStyle.Dash) oPen.DashStyle = DashStyle.Dash; if (oStyle == UnderlineStyle.Dot) oPen.DashStyle = DashStyle.Dot; oGraphics.DrawLine(oPen, nX + 4, nY + oSize.Height - 2, nX + oSize.Width, nY + oSize.Height - 2); } oPen.Dispose(); }