Treeview Custom Paint

  • Thread starter Thread starter JJBean
  • Start date Start date
J

JJBean

Hi All,

How do I create a custom paint treeview control or an
owner drawn treeview control ?

Any tutorials on this anywhere?

Thanks,
JJBean
 
i havent checked out this article yet, but do you know
offhand if it is it possible to draw single nodes for the
TreeView? (for instance to allow mixing of regular and
italic text)

Thanks!

-----Original Message-----
Hi,

There's an article on VB Accelerator outlining how this is done in VB6:

http://www.vbaccelerator.com/home/VB/Code/Controls/TreeVi ew/TreeView_Control/article.asp

Since it comes down to plain Win32 API, I think you should be able to
implement the same approach in C#. Pay most of your attention to how the
NM_CUSTOMDRAW notification is handled as this is the most useful part of the
code accompanying the article for you to start from.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi All,

How do I create a custom paint treeview control or an
owner drawn treeview control ?

Any tutorials on this anywhere?

Thanks,
JJBean

.
 
I DO know ohh-hand this is possible. I have even done it myself by drawing a
number of child nodes in parenthes in a different color (much like Outlook
Express does).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

woodBeeProgrammer said:
i havent checked out this article yet, but do you know
offhand if it is it possible to draw single nodes for the
TreeView? (for instance to allow mixing of regular and
italic text)

Thanks!

-----Original Message-----
Hi,

There's an article on VB Accelerator outlining how this is done in VB6:

http://www.vbaccelerator.com/home/VB/Code/Controls/TreeVi ew/TreeView_Control/article.asp

Since it comes down to plain Win32 API, I think you should be able to
implement the same approach in C#. Pay most of your attention to how the
NM_CUSTOMDRAW notification is handled as this is the most useful part of the
code accompanying the article for you to start from.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi All,

How do I create a custom paint treeview control or an
owner drawn treeview control ?

Any tutorials on this anywhere?

Thanks,
JJBean

.
 
Dmitriy, thanks, but how? (there is no
TreeNode.OnPaint :))

-----Original Message-----
I DO know ohh-hand this is possible. I have even done it myself by drawing a
number of child nodes in parenthes in a different color (much like Outlook
Express does).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

i havent checked out this article yet, but do you know
offhand if it is it possible to draw single nodes for the
TreeView? (for instance to allow mixing of regular and
italic text)

Thanks!

-----Original Message-----
Hi,

There's an article on VB Accelerator outlining how
this
is done in VB6:http://www.vbaccelerator.com/home/VB/Code/Controls/TreeVi
ew/TreeView_Control/article.asp

Since it comes down to plain Win32 API, I think you should be able to
implement the same approach in C#. Pay most of your attention to how the
NM_CUSTOMDRAW notification is handled as this is the most useful part of the
code accompanying the article for you to start from.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"JJBean" <[email protected]> wrote
in
message
Hi All,

How do I create a custom paint treeview control or an
owner drawn treeview control ?

Any tutorials on this anywhere?

Thanks,
JJBean

.

.
 
Right, there's no such thing. You should resort to overriding the tree's
parent control WndProc and handling WM_NOTIFY messages sent by the tree to
its parent. You will be interested in the NM_CUSTOMDRAW notification.

Please refer to Common Controls documentation in the MSDN Library for more
information. As the Framework provides no managed means to facilitate custom
drawing, plain Windows API is your only choice.
 
thanks for the response, but i'm not clear what you mean or what you did in
your Outlook bar type application.

Does the TreeView draw its window as a whole, or is it done node by node?
Can i write code for just one node, or do i need to manage the whole window?

TIA!


Dmitriy Lapshin said:
Right, there's no such thing. You should resort to overriding the tree's
parent control WndProc and handling WM_NOTIFY messages sent by the tree to
its parent. You will be interested in the NM_CUSTOMDRAW notification.

Please refer to Common Controls documentation in the MSDN Library for more
information. As the Framework provides no managed means to facilitate custom
drawing, plain Windows API is your only choice.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

woodBeeProgrammer said:
Dmitriy, thanks, but how? (there is no
TreeNode.OnPaint :))
 
TreeView allows for both of the approaches. I personally did custom node
drawing, as drawing all these connecting lines and [+] icons myself would be
such a pain! More than that, you can tell the TreeView to paint a node, and
then add something to what was painted by the tree view itself (it's exactly
what I did). If we take Outlook Express an an example, and assume there is
no need to have bold-face nodes, we should let the standard treeview to draw
the node text and the node icon, and then we will draw the number in
parenthes ourselves by using different color.

Please refer to the NM_CUSTOMDRAW notification message documentation - it
explains all custom drawing stages in detail.
 
Dmitriy, thanks. If anyone is interested, a sample for NM_CUSTOMDRAW is
CustDTv, currently at
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q248496 (wow, did
people ever program like that? sure looks almost like assembler!!)

Thanks again Dmitriy!


Dmitriy Lapshin said:
TreeView allows for both of the approaches. I personally did custom node
drawing, as drawing all these connecting lines and [+] icons myself would be
such a pain! More than that, you can tell the TreeView to paint a node, and
then add something to what was painted by the tree view itself (it's exactly
what I did). If we take Outlook Express an an example, and assume there is
no need to have bold-face nodes, we should let the standard treeview to draw
the node text and the node icon, and then we will draw the number in
parenthes ourselves by using different color.

Please refer to the NM_CUSTOMDRAW notification message documentation - it
explains all custom drawing stages in detail.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

woodBeeProgrammer said:
thanks for the response, but i'm not clear what you mean or what you did in
your Outlook bar type application.

Does the TreeView draw its window as a whole, or is it done node by node?
Can i write code for just one node, or do i need to manage the whole window?

TIA!
 
Back
Top