Support & Community

Custom node control

Previous Table of Contents Next

If you need specific node controls with custom behavior or appearance, you can easily create them. Depending on what you need, you should inherit your node control class from one of these:

  • BindableControl – for node controls that can bind to a node class`s member;
  • EditableControl – for editable node controls;
  • TextControl – for editable text node controls;
  • StaticTextControl – for non– editable text node controls;
  • PopupControl – for node controls that show popup on mouse click;
  • ExpandableControl – for expandable node controls.


For instance, here we`ll create a node control that is displays the color rectangle inside a node and changes the color on mouse click:

// custom node control class.
class MyNodeControl : BindableControl
{
  public MyNodeControl()
  {
    // bind to the Color node class`s property.
    DataFieldName = "Color";
  }
 
  protected override Size MeasureSize(Node pNode, DrawContext pContext)
  {
    // static node control size.
    return new Size(15, 15);
  }
 
  protected override void Draw(Node pNode, DrawContext pContext)
  {
    // display bounded color.
    Color cl = GetValue<Color>(pNode);
    using (SolidBrush br = new SolidBrush(cl))
    {
      pContext.Graphics.FillRectangle(br, pContext.Bounds);
    }
  }
 
  protected override void MouseDown(MouseActionArgs pArgs, DrawContext pContext)
  {
    // switch color on mouse click.
    Color cl = GetValue<Color>(pArgs.Node);
    Color clNew = (cl == Color.Red) ? Color.Blue : Color.Red;
    SetValue(pArgs.Node, clNew);
    OnControlChanged(eNodeControlChangeType.Look);
    }
}
 
// use our node control.
MyNodeControl nc = new MyNodeControl();
nc.AttachTo(tree);
 
NodeWithColor node = new NodeWithColor();
// initialize bounded property value.
node.Color = Color.Red;
node.AttachTo(tree);

Previous Top Next
Last news
Flexible TreeView v2.7
Sunday, 01 August 2010

Flexible TreeView v2.7 has been released with completely reimplemented data binding support.

Flexible TreeView v2.6
Thursday, 13 May 2010
Flexible TreeView v2.6 has been released with Visual Studio 2010 support, new NodeDateTime node control, data access great speed increase and much more.
Flexible TreeView v2.5
Saturday, 13 March 2010

Flexible TreeView v2.5 has been released with the new NodeProgressBar node control.

Latest release

Version:
Release date:
2.7.1
Aug 11, 2010


Copyright © 2006-2010 ARMSoft. All rights reserved.