Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
2 using System.Collections.Generic;
5 using System.Windows.Forms;
6 using System.Reflection;
7 using System.ComponentModel;
9 namespace Aga.Controls.Tree.NodeControls
11 public class NodeTextBox : BaseTextControl
13 private const int MinTextBoxWidth = 30;
19 protected override Size CalculateEditorSize(EditorContext context)
21 if (Parent.UseColumns)
22 return context.Bounds.Size;
25 Size size = GetLabelSize(context.CurrentNode, context.DrawContext, _label);
26 int width = Math.Max(size.Width + Font.Height, MinTextBoxWidth); // reserve a place for new typed character
27 return new Size(width, size.Height);
31 public override void KeyDown(KeyEventArgs args)
33 if (args.KeyCode == Keys.F2 && Parent.CurrentNode != null && EditEnabled)
40 protected override Control CreateEditor(TreeNodeAdv node)
42 TextBox textBox = CreateTextBox();
43 textBox.TextAlign = TextAlign;
44 textBox.Text = GetLabel(node);
45 textBox.BorderStyle = BorderStyle.FixedSingle;
46 textBox.TextChanged += EditorTextChanged;
47 textBox.KeyDown += EditorKeyDown;
48 _label = textBox.Text;
49 SetEditControlProperties(textBox, node);
53 protected virtual TextBox CreateTextBox()
58 protected override void DisposeEditor(Control editor)
60 var textBox = editor as TextBox;
61 textBox.TextChanged -= EditorTextChanged;
62 textBox.KeyDown -= EditorKeyDown;
65 private void EditorKeyDown(object sender, KeyEventArgs e)
67 if (e.KeyCode == Keys.Escape)
69 else if (e.KeyCode == Keys.Enter)
73 private string _label;
74 private void EditorTextChanged(object sender, EventArgs e)
76 var textBox = sender as TextBox;
77 _label = textBox.Text;
78 Parent.UpdateEditorBounds();
81 protected override void DoApplyChanges(TreeNodeAdv node, Control editor)
83 var label = (editor as TextBox).Text;
84 string oldLabel = GetLabel(node);
85 if (oldLabel != label)
87 SetLabel(node, label);
88 OnLabelChanged(node.Tag, oldLabel, label);
92 public override void Cut(Control control)
94 (control as TextBox).Cut();
97 public override void Copy(Control control)
99 (control as TextBox).Copy();
102 public override void Paste(Control control)
104 (control as TextBox).Paste();
107 public override void Delete(Control control)
109 var textBox = control as TextBox;
110 int len = Math.Max(textBox.SelectionLength, 1);
111 if (textBox.SelectionStart < textBox.Text.Length)
113 int start = textBox.SelectionStart;
114 textBox.Text = textBox.Text.Remove(textBox.SelectionStart, len);
115 textBox.SelectionStart = start;
119 public event EventHandler<LabelEventArgs> LabelChanged;
120 protected void OnLabelChanged(object subject, string oldLabel, string newLabel)
122 if (LabelChanged != null)
123 LabelChanged(this, new LabelEventArgs(subject, oldLabel, newLabel));