Solved

Custom TreeView

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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