|
Owner drawing
Tuesday, 08 September 2009
You can partially or completely override a node control`s appearance. To do that, you need to inherit your node control class from any core node control and override its appearance as stated below. Example: Here we derive our class from the core node control BindableControl (that allows you to bind the node control to a node class`s member) and design our node control appearance manually. Note that this is a very basic sample and you can use the NodePaintBox node control for that purpose. // The node control for displaying a color rectangle which color is in a node instance. class MyNodeControl : BindableControl { public MyNodeControl() { // bind this node control to the Color node property. DataFieldName = "Color"; } // measure the control`s occupied area size inside a node. protected override Size MeasureSize(Node pNode, DrawContext pContext) { // make static size but you can provide dynamic size as well. return new Size(20, 20); } // draw the node control content. protected override void Draw(Node pNode, DrawContext pContext) { Color cl; cl = GetColor(pNode); using (SolidBrush br = new SolidBrush(cl)) { pContext.Graphics.FillRectangle(br, pContext.Bounds); } } // get the bound data value. Color GetColor(Node pNode) { return GetValue<Color>(pNode); } } // use our custom node control. MyNodeControl ctrl = new MyNodeControl(); ctrl.AttachTo(tree); // add nodes. for(int i = 0; i < 50; i++) { NodeWithColor node = new NodeWithColor(); // initialize the color that the node control will display. node.Color = ((i%3) == 0) ? Color.Red : Color.Green; node.AttachTo(tree); } tree.Options.Node.AutoNodeHeight = true; |
|