473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 7346

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sean | last post by:
Hi all, I have a treeview and because I subclass the treeview and allow multiple selection to be done on the treeview, I have a problem changing the background color of the treeview. The...
0
by: kiran | last post by:
How to set background image for treeview control or transparent color as a background for treeview control in Windows forms..? Regards kiran
2
by: Rogers | last post by:
Hi,everyone: I want to add a background image to treeview control on my asp.net page,or if I can make it to be transparent,that would be okay to.if there and way to implement it? Thank you! ...
0
by: richie_hackett | last post by:
OK I have been tearing my hair out trying to get the Treeview webcontrol to display a background image. My current thinking is that mozilla allows you to render the treeview as a table instead...
0
by: Sarika | last post by:
Hi, I am a little confused about associating an image w/ the VB.NET TreeView Control. My specific requirement is that I want to associate an image w/ some specific nodes in the TreeView only. ...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
18
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and...
2
by: =?Utf-8?B?QU5V?= | last post by:
I have a tree view which i load completely at the time of my webpage load. When i click on the + signs of the parent nodes, it expands to show all of its children. Similarly, when i click on the...
4
by: =?Utf-8?B?UGF0cmlja1M=?= | last post by:
I'd like to be able to give a treeview in my application a nice smooth gradient as a background image, but I'm having trouble doing this. Webpages that I've seen so far seem to suggest using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.