?
Solved

Custom TreeView

Posted on 2010-11-19
3
Medium Priority
?
2,030 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 1000 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 1000 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

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…
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
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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