471,326 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

TreeView background Image

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.SupportsTransparentBac kColor,
false);
}

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

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

}

}

Aug 15 '08 #1
2 7192

"slg" wrote:
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.SupportsTransparentBac kColor,
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 15 '08 #2
slg
Thx!

"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:4F**********************************@microsof t.com...
>
"slg" wrote:
> 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.SupportsTransparentBac kColor,
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.

--
Happy Coding!
Morten Wennevik [C# MVP]

Aug 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by kiran | last post: by
2 posts views Thread by Rogers | last post: by
reply views Thread by richie_hackett | last post: by
reply views Thread by Sarika | last post: by
3 posts views Thread by Gary Dunne | last post: by
18 posts views Thread by =?Utf-8?B?TGkgV2VuZw==?= | last post: by
2 posts views Thread by =?Utf-8?B?QU5V?= | last post: by
4 posts views Thread by =?Utf-8?B?UGF0cmlja1M=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.