Click to See Complete Forum and Search --> : Extend treeview
laasunde
November 29th, 2006, 04:29 AM
I'm looking to extend the TreeView with a few features and looking for some advice. The features that I'd like to add are:
- Ability to enable and disable the checkbox for each node in a tree.
(Possibly hide a disabled checkbox)
- Ability to draw an icon\bmp after the node text (presently the icon is displayed before the node text).
- Ability to include a progressbar for each node in a tree.
(Possibly hide the progressbar when not used)
Does anyone have any relevant links. I'm unfamiliar with extending graphical components in .NET so would appreciate any input.
laasunde
November 30th, 2006, 06:31 AM
Just wanted to expand a bit on my inital post.
What I'm trying to achieve is an extention to the TreeView and TreeNode using C# and .NET code (no external libraries like I've seen some examples use).
Tried experimenting a bit but could not really figure it out. Have made an extended TreeNode and TreeView and I'm able to add the new Node to the new treeview. However I'm not able to add individual information to the nodes. In the code below I'm trying to catch the OnPaint and OnPaintBackgorund but the methods are not executed regardless of my actions in the application.
public class TreeViewEx : System.Windows.Forms.TreeView
{
public TreeViewEx() : base() { }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPrint(e);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
}
}
public class TreeNodeEx : System.Windows.Forms.TreeNode
{
public TreeNodeEx(string label, bool bold) : base(label)
{
m_FontBold= b;
}
private bool m_FontBold;
}
Say for instance for the first example all I wanted was to have an option to enable bold text for each node individually. How could I accomplish this tasks ?
Appreciate any hints \ advice.
laasunde
December 7th, 2006, 07:33 AM
Thought I'd give this post one more attempt. Is it really possible to extend the TreeView class to extend the graphics without having to re-implement most of the functionality?
This code fires OnPaint but still have no clue have to individually paint each TreeNode.
public class TreeViewEx : System.Windows.Forms.TreeView
{
const int WM_USER = 0x0400;
const int WM_NOTIFY = 0x004E;
const int WM_REFLECT = WM_USER + 0x1C00;
const int WM_PAINT = 0x000F;
public TreeViewEx() : base()
{
}
protected override void OnPaint(PaintEventArgs e)
{
Debug.Write("OnPrint\n");
base.OnPaint(e);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PAINT)
{
Graphics graphics = Graphics.FromHwnd(this.Handle);
PaintEventArgs pe = new PaintEventArgs(graphics, new Rectangle(0, 0, this.Width, this.Height));
OnPaint(pe);
}
base.WndProc(ref m);
}
}
Have also seen the usage of
SetStyle(ControlStyles.UserPaint, true);
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
but then it seems like I need to re-implement all of the drawing myself, not really extending the existing functionality. This seems like a lot of work.
What are the advantages of inherting from TreeView in terms of grahics? By using UserPaint it seems like Im starting at zero, I mean, what do I gain?
Appreciate any input \ advice.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.