Solved

Custom TreeView

Posted on 2010-11-19
3
1,975 Views
Last Modified: 2013-12-17
Experts,

I`m using VS2008, C#, 3.5

I`m creating a custom TreeView. I just want to change the way it looks. So I created a gradient background by over riding the OnPaintBackground(PaintEventArgs e). This works great.
Now when I try to create the Nodes. I don`t see anything. But the nodes are present, they just flicker for a second. Also when I click on the TreeView, the nodes are activated. It`s just that I don`t see them.

To draw the nodes I`m using

protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = true;
            base.OnDrawNode(e);
            //What goes in here? I might have some wrong code
        }

Help with some code will be greatly appreciated. Thanks - San
0
Comment
Question by:San24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 250 total points
ID: 34174900

I think you need to handle DrawNode event as well where you have to draw the node (when treeview's DrawMode proeprty is set to ownerdraw for custom treeviews). You can refer this link for more details => http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode.aspx
0
 
LVL 8

Assisted Solution

by:dericstone
dericstone earned 250 total points
ID: 34176176
Here's some code to get you started. I extracted this from my more complex code. Let me know if you cannot make it work.
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
    {
      SolidBrush foreBrush = (SolidBrush)SystemBrushes.HighlightText;
      SolidBrush backBrush = (SolidBrush)SystemBrushes.Highlight;
      e.Graphics.FillRectangle(backBrush, e.Bounds);
      e.Graphics.DrawString(e.Node.Text, e.Node.NodeFont, foreBrush,
        Rectangle.Inflate(e.Bounds, 2, 0));
    }

Open in new window

0
 

Author Comment

by:San24
ID: 34176471
@kris_per and dericstone - Let me give that a whirl and get back to you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question