Ejemplo n.º 1
0
        //******************************************************************
        /// <summary>
        /// Raises the DrawNode event.
        /// </summary>
        protected virtual void OnDrawNode(TreeViewerNodeEventArgs oArgs)
        {
            try
            {
                Debug.Assert(oArgs != null);

                if (DrawNode != null)
                {
                    DrawNode(this, oArgs);
                }
            }
            catch (Exception oException)
            {
                LogException(oException);
            }
        }
Ejemplo n.º 2
0
        //******************************************************************
        /// <summary>
        /// Raises the DrawNode event (this event comes from nodes in the
        /// tree). If the event handlers do not set the oArgs.Handled
        /// property to true, default node drawing is performed.
        /// </summary>
        protected virtual void OnDrawNode(TreeViewerNodeEventArgs oArgs)
        {
            try
            {
                Debug.Assert(oArgs != null);
                Debug.Assert(oArgs.Node != null);

                //**********************************************************
                // Raise the DrawNode event.

                if (DrawNode != null)
                {
                    DrawNode(this,oArgs);
                }

                //**********************************************************
                // If the oArgs.Handled property was not set to true by an
                // event handler, perform default node drawing.

                if (! oArgs.Handled)
                {
                    //******************************************************
                    // Determine the background, foreground and border
                    // colors.

                    Color oBackColor = oArgs.Node.BackColor;
                    Color oForeColor = oArgs.Node.ForeColor;
                    Color oBorderColor = oArgs.Node.BackColor;

                    //******************************************************
                    // Use different colors to highlight the selected node.

                    if (oArgs.Node == SelectedNode)
                    {
                        if (oArgs.Node.ContainsFocus)
                        {
                            //**********************************************
                            // Selected-node colors when the TreeViewer
                            // contains focus.

                            if (oBackColor == BackColor)
                            {
                                oBackColor = SystemColors.Highlight;
                                oForeColor = SystemColors.HighlightText;
                            }
                            oBorderColor = SystemColors.Highlight;
                        }
                        else
                        {
                            //**********************************************
                            // Selected-node colors when the TreeViewer does
                            // not contain focus.

                            if (oBackColor == BackColor)
                            {
                                oBackColor = SystemColors.Control;
                                oForeColor = SystemColors.ControlText;
                            }
                            oBorderColor = SystemColors.ControlDark;
                        }
                    }

                    //******************************************************
                    // The border color should be different than the
                    // TreeViewer's backround color.

                    if (oBorderColor == BackColor)
                    {
                        oBorderColor = oArgs.Node.ForeColor;
                    }

                    //******************************************************
                    // Create a graphics object. Get the width and height
                    // for drawing inside the node.

                    Graphics oGraphics = oArgs.Node.CreateGraphics();
                    int iWidth = oArgs.Node.Width - 1;
                    int iHeight = oArgs.Node.Height - 1;

                    //******************************************************
                    // Draw the background (background color).

                    Brush oBrush = new SolidBrush(oBackColor);
                    oGraphics.FillRectangle(oBrush,0,0,iWidth,iHeight);

                    //******************************************************
                    // Draw the text (foreground color), starting at offset
                    // (1,1) just inside the border.

                    oBrush = new SolidBrush(oForeColor);
                    string sText = oArgs.Node.Text;
                    if (sText == null)
                    {
                        sText = "";
                    }
                    oGraphics.DrawString(sText,oArgs.Node.Font,oBrush,1,1);

                    //******************************************************
                    // Draw the border (border color).

                    Pen oPen = new Pen(oBorderColor,1);
                    oGraphics.DrawLine(oPen,0,0,iWidth,0);
                    oGraphics.DrawLine(oPen,iWidth,0,iWidth,iHeight);
                    oGraphics.DrawLine(oPen,iWidth,iHeight,0,iHeight);
                    oGraphics.DrawLine(oPen,0,iHeight,0,0);
                }
            }
            catch (Exception oException)
            {
                LogException(oException);
            }
        }
Ejemplo n.º 3
0
        //******************************************************************
        /// <summary>
        /// Raises the MeasureNode event (this event comes from nodes in the
        /// tree). If the event handlers do not set the oArgs.Handled
        /// property to true, default node resizing is performed.
        /// </summary>
        private void OnMeasureNode(object oSender,
			TreeViewerNodeEventArgs oArgs)
        {
            OnMeasureNode(oArgs);
        }
Ejemplo n.º 4
0
        //******************************************************************
        /// <summary>
        /// Raises the DrawNode event (this event comes from nodes in the
        /// tree). If the event handlers do not set the oArgs.Handled
        /// property to true, default node drawing is performed.
        /// </summary>
        private void OnDrawNode(object oSender,
			TreeViewerNodeEventArgs oArgs)
        {
            OnDrawNode(oArgs);
        }
Ejemplo n.º 5
0
        //******************************************************************
        /// <summary>
        /// Raises the MeasureNode event (this event comes from nodes in the
        /// tree). If the event handlers do not set the oArgs.Handled
        /// property to true, default node resizing is performed.
        /// </summary>
        protected virtual void OnMeasureNode(TreeViewerNodeEventArgs oArgs)
        {
            try
            {
                Debug.Assert(oArgs != null);
                Debug.Assert(oArgs.Node != null);

                //**********************************************************
                // Call BeginUpdate() to disable redrawing the tree, but not
                // if redrawing was already disabled by the calling code.

                bool bCallEndUpdate = false;
                if (! IsUpdating)
                {
                    BeginUpdate();
                    bCallEndUpdate = true;
                }

                //**********************************************************
                // Raise the MeasureNode event.

                if (MeasureNode != null)
                {
                    MeasureNode(this,oArgs);
                }

                //**********************************************************
                // If the oArgs.Handled property was not set to true by an
                // event handler, perform default node resizing.

                if (! oArgs.Handled)
                {
                    //******************************************************
                    // Create a graphics object.

                    Graphics oGraphics = oArgs.Node.CreateGraphics();

                    //******************************************************
                    // Measure the size of the node's text.

                    string sText = oArgs.Node.Text;
                    if (sText == null)
                    {
                        sText = "";
                    }
                    SizeF oSizeF = oGraphics.MeasureString(
                        sText,oArgs.Node.Font);
                    float nWidth = oSizeF.Width;
                    float nHeight = oSizeF.Height;

                    //******************************************************
                    // Make sure we use at least a minimum size.

                    const string sMinimum = ".";
                    oSizeF = oGraphics.MeasureString(
                        sMinimum,oArgs.Node.Font);
                    if (nWidth < oSizeF.Width)
                    {
                        nWidth = oSizeF.Width;
                    }
                    if (nHeight < oSizeF.Height)
                    {
                        nHeight = oSizeF.Height;
                    }

                    //******************************************************
                    // Add a little width for italics or overhangs.

                    const int iExtraWidth = 1;
                    nWidth = nWidth	+ iExtraWidth;

                    //******************************************************
                    // Increase the size to include the borders.

                    nWidth = nWidth	+ 2;
                    nHeight = nHeight + 2;

                    //******************************************************
                    // Round up to an integer size.

                    oSizeF = new SizeF(nWidth,nHeight);
                    Size oSize = Size.Ceiling(oSizeF);

                    //******************************************************
                    // Resize the node.

                    oArgs.Node.Size = oSize;

                    //******************************************************
                    // Invalidate the control so the node will be repainted.

                    oArgs.Node.Invalidate();
                }

                //**********************************************************
                // Call EndUpdate() to redraw the tree, but not if redrawing
                // was already disabled by the calling code.

                if (bCallEndUpdate)
                {
                    EndUpdate();
                }
            }
            catch (Exception oException)
            {
                LogException(oException);
            }
        }
Ejemplo n.º 6
0
        //******************************************************************
        /// <summary>
        /// Raises the MeasureNode event.
        /// </summary>
        protected virtual void OnMeasureNode(TreeViewerNodeEventArgs oArgs)
        {
            try
            {
                Debug.Assert(oArgs != null);

                if (MeasureNode != null)
                {
                    MeasureNode(this,oArgs);
                }
            }
            catch (Exception oException)
            {
                LogException(oException);
            }
        }