TreeView background Image

S

slg

iam looking for code snippet or a sample of drawing background image for a
c# treeview control.

I tried following but i could not see the tree nodes only the ellipse shows
up.


TIA

public class xtree : System.Windows.Forms.TreeView
{
public xtree()

{

this.SetStyle(ControlStyles.UserPaint, true);

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor,
false);
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);

pevent.Graphics.DrawEllipse(pen, 0, 0, this.Width - 1, this.Height - 1);
}

}



}
 
M

Morten Wennevik [C# MVP]

slg said:
iam looking for code snippet or a sample of drawing background image for a
c# treeview control.

I tried following but i could not see the tree nodes only the ellipse shows
up.


TIA

public class xtree : System.Windows.Forms.TreeView
{
public xtree()

{

this.SetStyle(ControlStyles.UserPaint, true);

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor,
false);
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);

pevent.Graphics.DrawEllipse(pen, 0, 0, this.Width - 1, this.Height - 1);
}
}
}

When you use ControlStyles.UserPaint you are telling the system that it
should stop drawing the TreeView since you are going to do it. Since you
only draw the background you won't see any nodes in the tree.

I'm afraid that if you want a custom background you will also have to draw
the foreground.
 
S

slg

Thx!

Morten Wennevik said:
When you use ControlStyles.UserPaint you are telling the system that it
should stop drawing the TreeView since you are going to do it. Since you
only draw the background you won't see any nodes in the tree.

I'm afraid that if you want a custom background you will also have to draw
the foreground.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top