TreeView background Image

  • Thread starter Thread starter slg
  • Start date Start date
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);
}

}



}
 
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.
 
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.
 
Back
Top