|
NodePaintBox node control
Saturday, 12 September 2009
If you need to display data that has no built-in node control supports, you can display it manually using the NodePaintBox node control.
Example: // create the node control. NodePaintBox nc = new NodePaintBox(); nc.AttachTo(tree); // subscribe to the event to define the node control`s size and content. tree.MeasureNodeControl += tree_MeasureNodeControl; tree.PaintNodeControl += tree_PaintNodeControl; // add nodes, where our data will be displayed. Node n = new Node("1"); n.AttachTo(tree); n = new Node("2"); n.AttachTo(tree); private void tree_MeasureNodeControl(FlexibleTreeView pTreeview, MeasureObjectEventArgs pArgs) { // measure the node control size according to the specified node switch(pArgs.Node.Text) { case "1": pArgs.Size = new Size(20, 20); break; case "2": pArgs.Size = new Size(30, 30); break; } } // paint the node control content as a red rectangle. void tree_PaintNodeControl(FlexibleTreeView pTreeview, NodeControlDrawEventArgs pArgs) { using (Brush br = new SolidBrush(Color.Red)) { pArgs.Context.Graphics.FillRectangle(br, pArgs.Context.Bounds); } } |
|