示例#1
0
		// Invalidate from startNode down.
		internal void InvalidateDown(TreeNode startNode)
		{
			if (updating > 0 || this.nodes == null)
			{
				return;
			}
			
			// Find the position of startNode relative to the top node.
			int nodeFromTop = -1;
			TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
			while (nodes.MoveNext())
			{
				if (nodes.currentNode == topNode)
				{
					// We are at the top of the control.
					nodeFromTop = 0;
				}
				if (nodes.currentNode == startNode)
				{
					break;
				}
				if (nodeFromTop >= 0)
				{
					nodeFromTop++;
				}
			}
			// Calculate the y position of startNode.
			int y = nodeFromTop * ItemHeight;
			// Invalidate from this position down.
			// Start one pixel higher to cover the focus rectangle.
			Invalidate(new Rectangle(0, y - 1, ClientRectangle.Width, ClientRectangle.Height - y + 1));
		}
示例#2
0
		public Rectangle GetNodeBounds(TreeNode node)
		{
			if (node.parent != null)
			{
				int nodeFromTop = -1;
				TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
				while (nodes.MoveNext())
				{
					if (nodes.currentNode == topNode)
					{
						// We are at the top of the control.
						nodeFromTop = 0;
					}
					if (nodes.currentNode == node)
					{
						using(Graphics g = CreateGraphics())
						{
							return GetTextBounds(g, node, nodeFromTop, nodes.level);
						}
					}
					if (nodeFromTop >= 0)
					{
						nodeFromTop++;
					}
				}
			}
			return Rectangle.Empty;
		}
示例#3
0
		public TreeNode GetNodeAt(int x, int y)
		{
			int height = ItemHeight;
			int nodeFromTop = -1;
			TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
			while (nodes.MoveNext())
			{
				if (nodes.currentNode == topNode)
				{
					// We are now at the top of the control.
					nodeFromTop = 1;
				}
				if (nodeFromTop > -1)
				{
					if (y < height * nodeFromTop)
					{
						return nodes.currentNode;
					}
					nodeFromTop++;
				}
			}
			return null;
		}
示例#4
0
		private void vScrollBar_ValueChanged(object sender, EventArgs e)
		{
			int nodeFromTop = 0;
			TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
			while (nodes.MoveNext())
			{
				if (nodeFromTop == vScrollBar.Value)
				{
					topNode = nodes.currentNode;
					Invalidate();
					return;
				}
				nodeFromTop++;
			}
		}
示例#5
0
		void ProcessClick(int x, int y, bool rightMouse, ClickEvent clickEvent)
		{
			int nodeFromTop = -1;
			int height = ItemHeight;
			using(Graphics g = CreateGraphics())
			{
				// Iterate through all the nodes, looking for the bounds that match.
				TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
				while (nodes.MoveNext())
				{
					if (nodes.currentNode == topNode)
					{
						// We are now at the top of the control.
						nodeFromTop = 0;
					}
					if (nodeFromTop > -1)
					{
						// Check if the y matches this node.
						if (y < height * (nodeFromTop + 1))
						{							
							bool allowEdit = false;
							bool allowSelect = true;
							// Raise click or double click when called from MouseUp
							if(clickEvent == ClickEvent.Click)
							{
								OnClick(EventArgs.Empty);
							}
							else if(clickEvent == ClickEvent.DoubleClick)
							{
								OnDoubleClick(EventArgs.Empty);
							}
							// Clicking the image can be used to select.
							if (imageList == null || !GetImageBounds(nodeFromTop, nodes.level).Contains(x, y))
							{
								// Clicking the text can be used to edit and select.
								// if false then the hierarchy marker must have been clicked.
								if (GetTextBounds(g, nodes.currentNode, nodeFromTop, nodes.level).Contains(x, y))
								{
									allowEdit = true;
								}
								else
								{
									allowSelect = false;
								}
							}
							if (SelectedNode == nodes.Current && mouseClickTimer != null && mouseClickTimer.Enabled && (allowEdit || allowSelect))
							{
								mouseClickTimer.Stop();
								nodeToEdit = null;
								nodes.currentNode.Toggle();
								return;
							}
							if (allowSelect || rightMouse)
							{
								if (selectedNode == nodes.Current)
								{
									if (labelEdit && allowEdit && !rightMouse)
									{
										nodeToEdit = nodes.currentNode;
									}
								}
								else
								{
									nodeToEdit = null;
									// Do the events.
									TreeViewCancelEventArgs eventArgs = new TreeViewCancelEventArgs(nodes.currentNode, false, TreeViewAction.ByMouse);
									OnBeforeSelect(eventArgs);
									if (!eventArgs.Cancel)
									{
										SelectedNode = nodes.currentNode;
										OnAfterSelect(new TreeViewEventArgs(nodes.currentNode));
										Focus();
									}
								}
								if (rightMouse)
								{
									return;
								}
								if (mouseClickTimer == null)
								{
									mouseClickTimer = new Timer();
									mouseClickTimer.Tick +=new EventHandler(mouseClickTimer_Tick);
									mouseClickTimer.Interval = mouseEditTimeout;
								}
								mouseClickTimer.Start();
								break;
							}
						}
						nodeFromTop++;
					}
				}
			}
		}
示例#6
0
		// Non Microsoft member.
		protected override void OnMouseDown(MouseEventArgs e)
		{
			nodeToEdit = null;
			if (e.Button == MouseButtons.Left)
			{
				int nodeFromTop = -1;
				// Iterate through all the nodes, looking for the bounds that match.
				TreeView.NodeEnumerator nodes = new TreeView.NodeEnumerator(this.nodes);
				while (nodes.MoveNext())
				{
					if (nodes.currentNode == topNode)
					{
						// We are now at the top of the control.
						nodeFromTop = 0;
					}
					if (nodeFromTop > -1)
					{
						if (GetExpanderBounds(nodeFromTop, nodes.level).Contains(e.X, e.Y))
						{
							nodes.currentNode.Toggle();
							break;
						}
						else if (GetCheckBounds(nodeFromTop, nodes.level).Contains(e.X, e.Y))
						{
							TreeViewCancelEventArgs args = new TreeViewCancelEventArgs(nodes.currentNode, false, TreeViewAction.ByMouse);
							OnBeforeCheck(args);
							if (!args.Cancel)
							{
								nodes.currentNode.isChecked = !nodes.currentNode.isChecked;
								OnAfterCheck(new TreeViewEventArgs(nodes.currentNode, TreeViewAction.ByMouse));
							}

							Invalidate(GetCheckBounds(nodeFromTop, nodes.level));
							break;
			
						}
						nodeFromTop++;
					}
				}
			}
			else
			{
				ProcessClick(e.X, e.Y, true, ClickEvent.None);
			}
			base.OnMouseDown (e);
		}