/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="g"></param> /// <param name="offset"></param> /// <returns>Height of image</returns> private int RenderNodes(TristateTreeNodeCollection nodes, Graphics g, Point offset) { //The recursion shouldn't go so deep as to get a stackoverflow... for (int i = 0; i < nodes.Count; i++) { if (offset.Y < this.Height) { offset = nodes[i].Draw(g, offset); } } return(offset.Y); }
public TristateTreeView() { InitializeComponent(); this.vscrollbar.Dock = DockStyle.Right; this.g = this.CreateGraphics(); this.nodes = new TristateTreeNodeCollection(this); this.Paint += new PaintEventHandler(ProjectViewer_Paint); this.Resize += new EventHandler(TristateTreeView_Resize); this.MouseDown += new MouseEventHandler(TristateTreeView_MouseDown); this.MouseMove += new MouseEventHandler(TristateTreeView_MouseMove); this.vscrollbar.ValueChanged += new EventHandler(vscrollbar_ValueChanged); this.Controls.Add(vscrollbar); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); }
/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="g"></param> /// <param name="offset"></param> /// <returns>Height of image</returns> private int RenderNodes(TristateTreeNodeCollection nodes, Graphics g, Point offset) { //The recursion shouldn't go so deep as to get a stackoverflow... for (int i = 0; i < nodes.Count; i++) { if(offset.Y < this.Height) offset = nodes[i].Draw(g, offset); } return offset.Y; }
public TristateTreeNode(string text) { this.text = text; nodes = new TristateTreeNodeCollection(this); }
public TristateTreeNode() { nodes = new TristateTreeNodeCollection(this); }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="location"></param> /// <returns>New drawing offset (bottom left)</returns> public Point Draw(Graphics g, Point location) { if (HasToggle) { //Draw lines linking to parent if (this.parent is TristateTreeNode) { Pen pen = new Pen(Brushes.LightGray); pen.DashStyle = DashStyle.Dash; TristateTreeNodeCollection parentCNs = null; if (this.parent is TristateTreeNode) { parentCNs = ((TristateTreeNode)parent).nodes; } else { parentCNs = ((TristateTreeView)parent).Nodes; } int offset = 20; for (int i = 0; i < parentCNs.IndexOf(this); i++) { offset += parentCNs[i].BigSize.Height; } g.DrawLine(pen, location.X + 10, location.Y + 10, location.X - tabWidth + 10, location.Y + 10); //Vline up g.DrawLine(pen, location.X - tabWidth + 10, location.Y + 10, location.X - tabWidth + 10, location.Y - offset + 10); } //Draw actual element if (location.Y > -20 && location.Y < TreeView.Height + 20) { if (HasCheckBox) { Point stringLocation = new Point( location.X + 20 + 19, location.Y + (20 - (int)g.MeasureString(text, this.GetFont()).Height) / 2 ); g.DrawImage(GetToggleBitmap(), new Rectangle(location, new Size(19, 20))); g.DrawImage(GetCheckboxBitmap(), new Rectangle(new Point(location.X + 19, location.Y), new Size(20, 20))); if (this.TreeView.SelectedNodes.Contains(this)) { g.FillRectangle(Brushes.LightGray, new Rectangle(stringLocation, g.MeasureString(this.text, this.GetFont()).ToSize())); } g.DrawString(this.text, this.GetFont(), Brushes.Black, stringLocation ); } else { Point stringLocation = new Point( location.X + 19, location.Y + (20 - (int)g.MeasureString(text, this.GetFont()).Height) / 2 ); g.DrawImage(GetToggleBitmap(), new Rectangle(location, new Size(19, 20))); if (this.TreeView.SelectedNode == this) { g.FillRectangle(Brushes.LightGray, new Rectangle(stringLocation, g.MeasureString(this.text, this.GetFont()).ToSize())); } g.DrawString(this.text, this.GetFont(), Brushes.Black, stringLocation ); } } //Draw toggle if (toggle) { Point offset = new Point( location.X + tabWidth, location.Y + this.Size.Height ); for (int i = 0; i < nodes.Count; i++) { if (offset.Y < TreeView.Height) { offset = nodes[i].Draw(g, offset); } } //RenderNodes(nodes[i].Nodes, g, offset); //offset.X -= tabWidth; } return(GetDrawingOffset(g, location)); } else { //Draw lines linking to parent if (this.parent is TristateTreeNode) { Pen pen = new Pen(Brushes.LightGray); pen.DashStyle = DashStyle.Dash; TristateTreeNodeCollection parentCNs = null; if (this.parent is TristateTreeNode) { parentCNs = ((TristateTreeNode)parent).nodes; } else { parentCNs = ((TristateTreeView)parent).Nodes; } int offset = 20; for (int i = 0; i < parentCNs.IndexOf(this); i++) { offset += parentCNs[i].BigSize.Height; } g.DrawLine(pen, location.X + 10, location.Y + 10, location.X - tabWidth + 10, location.Y + 10); //Vline up g.DrawLine(pen, location.X - tabWidth + 10, location.Y + 10, location.X - tabWidth + 10, location.Y - offset + 10); } if (HasCheckBox) { Point stringLocation = new Point( location.X + 19 + 20, location.Y + (20 - (int)g.MeasureString(text, this.GetFont()).Height) / 2 ); g.DrawImage(GetCheckboxBitmap(), new Rectangle( new Point(location.X + 19, location.Y), new Size(20, 20))); if (this.TreeView.SelectedNode == this) { g.FillRectangle(Brushes.LightGray, new Rectangle(stringLocation, g.MeasureString(this.text, this.GetFont()).ToSize())); } g.DrawString(this.text, this.GetFont(), Brushes.Black, stringLocation ); } else { Point stringLocation = new Point( location.X + 19 + 20, location.Y + (20 - (int)g.MeasureString(text, this.GetFont()).Height) / 2 ); if (this.TreeView.SelectedNode == this) { g.FillRectangle(Brushes.LightGray, new Rectangle(stringLocation, g.MeasureString(this.text, this.GetFont()).ToSize())); } g.DrawString(this.text, this.GetFont(), Brushes.Black, stringLocation ); } return(GetDrawingOffset(g, location)); } }