Example #1
0
        private bool showPlusMinus(ThreeStateTreeNode threeStateNode)
        {
            bool showPlusMinus = this.ShowPlusMinus;

            if (threeStateNode != null)
            {
                showPlusMinus &= threeStateNode.ShowPlusMinus;
            }
            return(showPlusMinus);
        }
Example #2
0
        private void CheckNodes(TreeNode node, CheckState state)
        {
            ThreeStateTreeNode tstn = node as ThreeStateTreeNode;

            if (tstn != null && tstn.HasCheckBox)
            {
                tstn.CheckState = state;
                tstn.Checked    = !tstn.Checked; //TODO
            }

            foreach (TreeNode n in node.Nodes)
            {
                CheckNodes(n, state);
            }
        }
Example #3
0
        private void SetNextState(TreeNode node)
        {
            ThreeStateTreeNode tstn = node as ThreeStateTreeNode;

            if (tstn != null)
            {
                tstn.CheckState = GetNextState(tstn.CheckState);
            }

            node.Checked = !node.Checked;

            TreeViewEventArgs args = new TreeViewEventArgs(node);

            this.OnAfterCheck(args);
        }
Example #4
0
        private void CountNodes(TreeNode node, ref int countChecked, ref int countUncheckd, ref int countNodes)
        {
            ThreeStateTreeNode tstn = node as ThreeStateTreeNode;

            if (tstn != null && tstn.HasCheckBox)
            {
                countNodes++;
                if (tstn.CheckState == CheckState.Checked)
                {
                    countChecked++;
                }
                else if (tstn.CheckState == CheckState.Unchecked)
                {
                    countUncheckd++;
                }
            }

            foreach (TreeNode n in node.Nodes)
            {
                CountNodes(n, ref countChecked, ref countUncheckd, ref countNodes);
            }
        }
Example #5
0
        private void ThreeStateTreeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            ThreeStateTreeNode threeStateNode = e.Node as ThreeStateTreeNode;

            // farben für den text einstellen
            Brush brush;
            Brush brushBackground;

            if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
            {
                brush           = SystemBrushes.HighlightText;
                brushBackground = SystemBrushes.Highlight;
            }
            else
            {
                brush           = SystemBrushes.ControlText;
                brushBackground = SystemBrushes.ControlLightLight;
            }

            // den platz für das node festlegen
            Rectangle nodeRect = new Rectangle(e.Bounds.Location, e.Bounds.Size);

            // je nach level nach rechts einrücken
            nodeRect.X     += this.Indent * threeStateNode.Level;
            nodeRect.Width -= this.Indent * threeStateNode.Level;

            // plus minus malen
            if (showPlusMinus(threeStateNode))
            {
                if (e.Node.Nodes.Count > 0)
                {
                    Image img;
                    if (threeStateNode.IsExpanded)
                    {
                        img = this.images.Images[0];
                    }
                    else
                    {
                        img = this.images.Images[1];
                    }

                    e.Graphics.DrawImageUnscaled(img, nodeRect);
                }
                nodeRect.X     += this.plusMinusWidth;
                nodeRect.Width -= this.plusMinusWidth;
            }

            // checkbox malen
            if (threeStateNode != null && threeStateNode.HasCheckBox)
            {
                System.Windows.Forms.VisualStyles.CheckBoxState state;
                if (threeStateNode.CheckState == CheckState.Checked)
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                }
                else if (threeStateNode.CheckState == CheckState.Unchecked)
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                }
                else
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal;
                }

                CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(nodeRect.X, nodeRect.Y + 2), state);
                Size s = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);

                nodeRect.X     += this.checkBoxWidth;
                nodeRect.Width -= this.checkBoxWidth;
            }

            // hintergrund malen
            Rectangle rec = new Rectangle(nodeRect.X, nodeRect.Y, nodeRect.Width, nodeRect.Height);

            e.Graphics.FillRectangle(brushBackground, rec);

            Font f;

            if (threeStateNode != null && threeStateNode.Bold)
            {
                f = new Font(this.Font, FontStyle.Bold);
            }
            else
            {
                f = this.Font;
            }

            // text malen
            Rectangle recText = new Rectangle(nodeRect.X + 1, nodeRect.Y + 1, nodeRect.Width, nodeRect.Height);

            e.Graphics.DrawString(e.Node.Text,
                                  f,
                                  brush,
                                  recText,
                                  new StringFormat(StringFormatFlags.NoWrap));
        }