By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

treeview

P: n/a
hi i have a set of bitmaps in an array.
and i want to add it to a imagelist so that i can show those images in my
treeview.
imageList2.Images.Add (Image.FromHbitmap (picture.Bitmap)); //cant use this
gives me an error

do i need to convert from bitmap to a memory stream?

thanx
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The following is an exact example which works:

Image i = (Image)Bitmap.FromFile(@"C:\WINDOWS\blue lace 16.bmp");
ImageList il = new ImageList();

il.Images.Add(i);

TreeView tv = new TreeView();

tv.ImageList = il;
tv.Nodes.Add("root");
tv.Nodes[0].ImageIndex = 0; //set the image to the first item

this.Controls.Add(tv);

Cheers,
Branimir
--
Branimir Giurov
MCSD.NET, MCDBA
eAgility LLC
"frazer" <ic***@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
hi i have a set of bitmaps in an array.
and i want to add it to a imagelist so that i can show those images in my
treeview.
imageList2.Images.Add (Image.FromHbitmap (picture.Bitmap)); //cant use this gives me an error

do i need to convert from bitmap to a memory stream?

thanx

Nov 16 '05 #2

P: n/a
frazer wrote:
hi i have a set of bitmaps in an array.
and i want to add it to a imagelist so that i can show those images in my
treeview.
There is ImageList.ImageSize property that should correspond with
size of images. If it isn't then images will be resized (with
possible loss of quality).
imageList2.Images.Add (Image.FromHbitmap (picture.Bitmap)); //cant use this
gives me an error
I believe that your picture.Bitmap does not returns IntPtr.
ImageList.ImageCollection.Add method takes "Image" or "Icon" parameter.
do i need to convert from bitmap to a memory stream?

thanx


try this:

Bitmap[] bmpArray; // your array of bitmaps

// ... bmpArray fill

for(int i=0; i<bmpArray.Length; i++) {
imageList2.Images.Add(bmpArray[i]);
}

If my sample will not do what you want or throws exception
then send feedback with possible StackTrace.

Regards

Marcin
Nov 16 '05 #3

P: n/a
Hi,

I think your approach is a little bit overcomplicated. The Add method
accepts a System.Drawing.Image, and System.Drawing.Bitmap is inherited from
System.Drawing.Image. So it should be sufficient to use the following code
(given the Bitmap property returns an instance of System.Drawing.Bitmap):

imageList2.Images.Add (picture.Bitmap);

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"frazer" <ic***@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
hi i have a set of bitmaps in an array.
and i want to add it to a imagelist so that i can show those images in my
treeview.
imageList2.Images.Add (Image.FromHbitmap (picture.Bitmap)); //cant use this gives me an error

do i need to convert from bitmap to a memory stream?

thanx


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.