Ejemplo n.º 1
0
        //The actual drawing code
        bool Infragistics.Win.IUIElementDrawFilter.DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams)
        {
            Infragistics.Win.UIElement aUIElement;
            System.Drawing.Graphics    g;
            UltraTreeNode aNode;

            //If there's no DropHighlight node or no position specified, then we don't need to draw anything special.
            //Just exit Function
            if ((mvarDropHighLightNode == null) || (mvarDropLinePosition == DropLinePositionEnum.None))
            {
                return(false);
            }

            //Create a new QueryStateAllowedForNodeEventArgs object to pass to the event
            QueryStateAllowedForNodeEventArgs eArgs = new QueryStateAllowedForNodeEventArgs();

            //Initialize the object with the correct info
            eArgs.Node             = mvarDropHighLightNode;
            eArgs.DropLinePosition = this.mvarDropLinePosition;

            //Default to all states allowed.
            eArgs.StatesAllowed = DropLinePositionEnum.All;

            //Raise the event
            this.QueryStateAllowedForNode(this, eArgs);

            //Check to see if the user allowed the current state for this node. If not, exit function
            if ((eArgs.StatesAllowed & mvarDropLinePosition) != mvarDropLinePosition)
            {
                return(false);
            }

            //Get the element being drawn
            aUIElement = drawParams.Element;

            //Determine which drawing phase we are in.
            switch (drawPhase)
            {
            case Infragistics.Win.DrawPhase.BeforeDrawElement:
            {
                //We are in BeforeDrawElement, so we are only concerned with drawing the OnNode state.
                if ((mvarDropLinePosition & DropLinePositionEnum.OnNode) == DropLinePositionEnum.OnNode)
                {
                    //Check to see if we are drawing a NodeTextUIElement
                    if (aUIElement.GetType() == typeof(Infragistics.Win.UltraWinTree.NodeTextUIElement))
                    {
                        //Get a reference to the node that this NodeTextUIElement is associated with
                        aNode = (UltraTreeNode)aUIElement.GetContext(typeof(UltraTreeNode));

                        //See if this is the DropHighlightNode
                        if (aNode.Equals(mvarDropHighLightNode))
                        {
                            //Set the ForeColor and Backcolor of the node to the DropHighlight colors
                            //Note that AppearanceData only affects the node for this one paint. It will not
                            //change any properties of the node
                            drawParams.AppearanceData.BackColor = mvarDropHighLightBackColor;
                            drawParams.AppearanceData.ForeColor = mvarDropHighLightForeColor;
                        }
                    }
                }
                break;
            }

            case Infragistics.Win.DrawPhase.AfterDrawElement:
            {
                //We're in AfterDrawElement.  So the only states we are conderned with are Below and Above
                //Check to see if we are drawing the Tree Element
                if (aUIElement.GetType() == typeof(Infragistics.Win.UltraWinTree.UltraTreeUIElement))
                {
                    //Declare a pen to us for drawing Droplines
                    System.Drawing.Pen p = new System.Drawing.Pen(mvarDropLineColor, mvarDropLineWidth);

                    //Get a reference to the Graphics object we are drawing to.
                    g = drawParams.Graphics;

                    // Get the NodeSelectableAreaUIElement for the current DropNode. We will use this for
                    // positioning and sizing the DropLine
                    Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement tElement;
                    tElement = (Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement)drawParams.Element.GetDescendant(typeof(Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement), mvarDropHighLightNode);
                    if (tElement == null)
                    {
                        return(false);
                    }

                    //The left edge of the DropLine
                    int LeftEdge = tElement.Rect.Left - 4;

                    //We need a reference to the control to determine the right edge of the line
                    UltraTree aTree;
                    aTree = (UltraTree)tElement.GetContext(typeof(UltraTree));
                    int RightEdge = aTree.DisplayRectangle.Right - 4;

                    //Used to store the Vertical position of the DropLine
                    int LineVPosition;

                    if ((mvarDropLinePosition & DropLinePositionEnum.AboveNode) == DropLinePositionEnum.AboveNode)
                    {
                        //Draw line above node
                        LineVPosition = mvarDropHighLightNode.Bounds.Top;
                        g.DrawLine(p, LeftEdge, LineVPosition, RightEdge, LineVPosition);
                        p.Width = 1;
                        g.DrawLine(p, LeftEdge, LineVPosition - 3, LeftEdge, LineVPosition + 2);
                        g.DrawLine(p, LeftEdge + 1, LineVPosition - 2, LeftEdge + 1, LineVPosition + 1);
                        g.DrawLine(p, RightEdge, LineVPosition - 3, RightEdge, LineVPosition + 2);
                        g.DrawLine(p, RightEdge - 1, LineVPosition - 2, RightEdge - 1, LineVPosition + 1);
                    }

                    if ((mvarDropLinePosition & DropLinePositionEnum.BelowNode) == DropLinePositionEnum.BelowNode)
                    {
                        //Draw Line below node
                        LineVPosition = mvarDropHighLightNode.Bounds.Bottom;
                        g.DrawLine(p, LeftEdge, LineVPosition, RightEdge, LineVPosition);
                        p.Width = 1;
                        g.DrawLine(p, LeftEdge, LineVPosition - 3, LeftEdge, LineVPosition + 2);
                        g.DrawLine(p, LeftEdge + 1, LineVPosition - 2, LeftEdge + 1, LineVPosition + 1);
                        g.DrawLine(p, RightEdge, LineVPosition - 3, RightEdge, LineVPosition + 2);
                        g.DrawLine(p, RightEdge - 1, LineVPosition - 2, RightEdge - 1, LineVPosition + 1);
                    }
                }
                break;
            }
            }
            return(false);
        }
 /// <summary>
 /// Called during the drawing operation of a UIElement for a specific phase
 /// of the operation. This will only be called for the phases returned
 /// from the GetPhasesToFilter method.
 /// </summary>
 /// <param name="drawPhase">Contains a single bit which identifies the current draw phase.</param>
 /// <param name="drawParams">The <see cref="T:Infragistics.Win.UIElementDrawParams" /> used to provide rendering information.</param>
 /// <returns>
 /// Returning true from this method indicates that this phase has been handled and the default processing should be skipped.
 /// </returns>
 public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams)
 {
     return(true);
 }