Exemple #1
0
 // Constructor.
 public NodeEnumeratorEx(TreeNodeExCollection nodes)
 {
     this.nodes = nodes;
     Reset();
 }
Exemple #2
0
 public TreeViewEx()
     : base()
 {
     hideSelection = true;
     indent = 19;
     itemHeight = -1;
     scrollable = true;
     showLines = true;
     showPlusMinus = true;
     showRootLines = true;
     root = new TreeNodeEx(this);
     root.Expand();
     nodes = new TreeNodeExCollection(root);
     BackColor = SystemColors.Window;
     ForeColor = SystemColors.WindowText;
     SetStyle(Forms.ControlStyles.StandardClick, false);
     // Switch on double buffering.
     SetStyle(Forms.ControlStyles.DoubleBuffer | Forms.ControlStyles.AllPaintingInWmPaint | Forms.ControlStyles.UserPaint, true);
 }
Exemple #3
0
		public void EnsureVisible()
		{
			TreeViewEx.NodeEnumeratorEx nodes;
			int nodeFromTop;
			int nodeNo;
			while (true)
			{
				// Find "this" node number and position from the top control.
				nodeFromTop = -1;
				nodeNo = 0;
				bool nodeFound = false;
				nodes = new TreeViewEx.NodeEnumeratorEx(treeView.nodes);
				while (nodes.MoveNext())
				{
					if (nodes.currentNode == treeView.topNode)
					{
						// We are at the top of the control.
						nodeFromTop = 0;
					}
					if (nodes.currentNode == this)
					{
						if (nodeFromTop < 0)
						{
							treeView.topNode = this;
							treeView.Invalidate();
							return;
						}
						nodeFound = true;
						break;
					}
					if (nodeFromTop >= 0)
					{
						nodeFromTop++;
					}
					nodeNo++;
				}


				if (nodeFound)
				{
					break;
				}
				else
				{
					// Make sure all parents are expanded and see if its now visible.
					TreeNodeEx node = this;
					TreeNodeEx highestNode = node;
					for (; node != null; node = node.Parent)
					{
						node.expanded = true;
						highestNode = node;
					}
					treeView.InvalidateDown(highestNode);
				}
			}

			int visibleNodes = treeView.VisibleCountActual;
			// See if its already visible.
			if (nodeFromTop < visibleNodes)
			{
				return;
			}

			// Set the top node no we want to make this node 1 up from the bottom.
			nodeFromTop = nodeNo - visibleNodes + 1;
			if (nodeFromTop < 0)
			{
				nodeFromTop = 0;
			}

			// Find the node corresponding to this node no.
			nodes.Reset();
			nodeNo = 0;
			while (nodes.MoveNext())
			{
				if (nodeFromTop == nodeNo)
				{
					treeView.topNode = nodes.currentNode;
					treeView.Invalidate();
					break;
				}
				nodeNo++;
			}
		}