Solved

Custom TreeView

Posted on 2010-11-19
3
1,955 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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 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